/// <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 gv_Details_RowCommand(object sender, GridViewCommandEventArgs e) { string message = string.Empty; if (e.CommandName == "EditRow") { ViewState["SchooldropreasonID"] = e.CommandArgument; GetSchoolDropDetails(); SetUpdateMode(true); ScriptManager.RegisterStartupScript(this, this.GetType(), "Added", "setDirty();", true); } else if (e.CommandName == "DeleteRow") { int reasonid = Convert.ToInt32(e.CommandArgument); SchoolDropBLL SchoolDropBLLObj = new SchoolDropBLL(); message = SchoolDropBLLObj.Delete(Convert.ToInt32(e.CommandArgument)); if (string.IsNullOrEmpty(message) || message == "" || message == "null") { message = "Data Deleted successfully"; } ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Added", "alert('" + message + "');", true); cleardetails(); SetUpdateMode(false); BindGrid(); } }
/// <summary> ///To delete a row from grid /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void gv_Details_RowDeleting(object sender, GridViewDeleteEventArgs e) { int reasonid = Int32.Parse(gv_Details.DataKeys[e.RowIndex].Value.ToString()); SchoolDropBLL SchoolDropBLLObj = new SchoolDropBLL(); try { SchoolDropBLLObj.Delete(reasonid); BindGrid(); } catch (Exception ee) { string errorMsg = ee.Message.ToString(); Response.Write(errorMsg); } finally { SchoolDropBLLObj = null; } gv_Details.EditIndex = -1; BindGrid(); }