protected void btnDelete_Click(object sender, EventArgs e) { try { //Get the button that raised the event LinkButton btn = (LinkButton)sender; //Get the row that contains this button GridViewRow gvr = (GridViewRow)btn.NamingContainer; if (gvr.RowIndex >= 0) { DataTable tableSource = (DataTable)ViewState["MASTER_DATA"]; string portfolioMasterId = tableSource.Rows[gvr.RowIndex]["ROWID"].ToString(); StockManager stockManager = new StockManager(); if (stockManager.DeletePortfolio(portfolioMasterId)) { Session["STOCKPORTFOLIOMASTERROWID"] = null; Session["STOCKPORTFOLIONAME"] = null; Session["STOCKSELECTEDINDEXPORTFOLIO"] = null; ViewState["MASTER_DATA"] = null; GetPortfolios(); } } } catch (Exception ex) { Page.ClientScript.RegisterStartupScript(GetType(), "myScript", "alert('Error occurred while deleting portfolio. Please try again. :" + ex.Message + "');", true); } gvPortfolioMaster.EditIndex = -1; gvPortfolioMaster.Columns[3].Visible = false; }
protected void buttonDelete_Click(object sender, EventArgs e) { //if (deletePortfolioName.Equals("-1") == false) if (ddlFiles.SelectedIndex > 0) { string portfolioMasterId = ddlFiles.SelectedValue; StockManager stockManager = new StockManager(); if (stockManager.DeletePortfolio(portfolioMasterId)) { if (stockManager.getPortfolioCount(Session["EMAILID"].ToString()) > 0) { Response.Redirect("~/mselectportfolio.aspx"); } else { Response.Redirect("~/mnewportfolio.aspx"); } } else { labelSelectedFile.Text = "Problem encountered while trying to delete portfolio. Please try again later"; //Response.Write("<script language=javascript>alert('"+ common.noPortfolioSelectedToDelete +"')</script>"); Page.ClientScript.RegisterStartupScript(GetType(), "myScript", "alert('Problem encountered while trying to delete portfolio. Please try again later');", true); } } else { labelSelectedFile.Text = "Selected File: Please select portfolio to delete"; //Response.Write("<script language=javascript>alert('"+ common.noPortfolioSelectedToDelete +"')</script>"); Page.ClientScript.RegisterStartupScript(GetType(), "myScript", "alert('" + common.noPortfolioSelectedToDelete + "');", true); } }