Click here to Skip to main content
16,004,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

In gridview i have added a dynamic button as "REVISE".
now what i want is when i click on this button, A new ROW should be inserted below the clicked row of gridview with the two buttons.. "YES" and "NO"

here i m providing u the code. which i have coded but i m not getting what i want,
Please Help
C#
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"
        }      
    }
}
Posted
Updated 11-Mar-12 18:35pm
v2

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900