protected void GVDetails_RowDataBound(object sender, GridViewRowEventArgs e) { //Adding the buttons Button apr = new Button(); Button rej = new Button(); apr.Text = "Approved"; rej.Text = "Reject"; //assignnig command name apr.CommandName = "Approved"; rej.CommandName = "Reject"; if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Cells[10].Controls.Add(apr); e.Row.Cells[11].Controls.Add(rej); } } protected void GVDetails_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Approved") { GridViewRow row = (GridViewRow)((Control)e.CommandSource).NamingContainer; Id = Convert.ToInt32(GVDetails.DataKeys[row.RowIndex].Value.ToString()); // for this we have to set the "DataKeyNames="doc_id" in HTML file Response.Write("the doc_id is = " + Id); cn.Open(); SqlCommand cmd = new SqlCommand("update tdocument set STAT=@STAT where doc_id=" + Id + "", cn); cmd.Parameters.Add("@STAT", SqlDbType.VarChar).Value = "APPROVED"; cmd.ExecuteNonQuery(); cn.Close(); SendApprovedMails(); // calling the method to send mails to everyone Response.Redirect(Request.RawUrl); // this line is to refresh the page without using "response.redirect" } else if (e.CommandName == "Reject") //HERE PLEASE TELL ME HOW SHOULD I CODE FOR DELETE { Response.Write("Reject"); GridViewRow row = (GridViewRow)((Control)e.CommandSource).NamingContainer; Id = Convert.ToInt32(GVDetails.DataKeys[row.RowIndex].Value.ToString()); // for this we have to set the "DataKeyNames="doc_id" in HTML file Response.Write("the doc_id is = " + Id); cn.Open(); SqlCommand cmd = new SqlCommand("update tdocument set STAT=@STAT where doc_id=" + Id + "", cn); cmd.Parameters.Add("@STAT", SqlDbType.VarChar).Value = "Pending"; cmd.ExecuteNonQuery(); cn.Close(); row.Visible = false; // code for deleteing the row from GridView sendRejectMails(); Response.Redirect(Request.RawUrl); // this line is to refresh the page without using "response.redirect" } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)