/// <summary> /// Set edit mode for edit comand /// Delete data from the database for delete comand /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void grdlivelihood_RowCommand(object sender, GridViewCommandEventArgs e) { string message = string.Empty; if (e.CommandName == "EditRow") { ViewState["ITEMID"] = e.CommandArgument; int itemid = Convert.ToInt32(ViewState["ITEMID"]); GridViewRow row = (GridViewRow)((ImageButton)e.CommandSource).NamingContainer; if (row != null) { livelihoodTextBox.Text = row.Cells[1].Text.ToString(); } SetUpdateMode(true); ScriptManager.RegisterStartupScript(this, this.GetType(), "Added", "setDirty();", true); } else if (e.CommandName == "DeleteRow") { LivelihoodBLL objLivelihoodBLL = new LivelihoodBLL(); message = objLivelihoodBLL.DeleteLivelihood(Convert.ToInt32(e.CommandArgument)); if (string.IsNullOrEmpty(message) || message == "" || message == "null") { message = "Data deleted successfully"; } cleardetails(); SetUpdateMode(false); BindGrid(false, true); } if (message != "") { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Added", "alert('" + message + "');", true); } }
/// <summary> /// To delete row based on ID /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void grdlivelihood_RowDeleting(object sender, GridViewDeleteEventArgs e) { int itemid = Int32.Parse(grdlivelihood.DataKeys[e.RowIndex].Value.ToString()); LivelihoodBLL objLivelihoodBLL = new LivelihoodBLL(); try { objLivelihoodBLL.DeleteLivelihood(itemid); BindGrid(true, true); } catch (Exception ee) { string errorMsg = ee.Message.ToString(); } finally { objLivelihoodBLL = null; } grdlivelihood.EditIndex = -1; BindGrid(true, true); }