public partial class RenewDocuments : System.Web.UI.Page { SqlConnection cn = new SqlConnection("Data Source=FRE-GGN-MSSTEST;Initial Catalog=DMS1;Integrated Security=True"); SqlDataAdapter sda; DataSet ds; int Id; protected void Page_Load(object sender, EventArgs e) { cn.Open(); FillData(); } public void FillData() { // code for getting the records that are between 2 days period string str = "select * from tdocument where @tdy between upload_date and expire_date"; SqlCommand cmd = new SqlCommand(str, cn); cmd.Parameters.Add("@tdy", SqlDbType.Date).Value = DateTime.Now; sda = new SqlDataAdapter(); sda.SelectCommand = cmd; ds = new DataSet(); sda.Fill(ds); if (ds == null || ds.Tables[0].Rows.Count == 0) // condition that checks whether there is any records or not { LblNoRecords.Text = "No Records have been Uploaded Recently"; } else { cn.Close(); sda.Dispose(); //Adding two columns in datatable. ds.Tables[0].Columns.Add("REVISE"); GVRenewalDocuments.DataSource = ds; GVRenewalDocuments.DataBind(); } } protected void GVRenewalDocuments_RowDataBound(object sender, GridViewRowEventArgs e) { //Adding the buttons Button rev = new Button(); rev.Text = "Revise"; //assignnig command name rev.CommandName = "REVISE"; if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Cells[10].Controls.Add(rev); } } protected void GVRenewalDocuments_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "REVISE") { GridViewRow row = (GridViewRow)((Control)e.CommandSource).NamingContainer; Id = Convert.ToInt32(GVRenewalDocuments.DataKeys[row.RowIndex].Value.ToString()); DataTable dt = ds.Tables[0]; // THIS IS WHAT I HAVE DONE DataRow row1 = dt.NewRow(); dt.Rows.Add(row1); GVRenewalDocuments.DataSource = dt; GVRenewalDocuments.DataBind(); //AddNewRow(); 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)