Smile Azeez Smile Azeez - 1 year ago 171
ASP.NET (C#) Question

add new row in gridview after binding C#,

enter image description here

I want to add a new blank row to the gridview after binding as seen in the picture when clicking the link button below. The textboxes inside the gridview should remain the same if there is any data entered in it. just want to add one row. please help me. Thanks in advance.

Answer Source

you can try the following code

protected void Button1_Click(object sender, EventArgs e)
       DataTable dt = new DataTable();

       if (dt.Columns.Count == 0)
           dt.Columns.Add("PayScale", typeof(string));
           dt.Columns.Add("IncrementAmt", typeof(string));
           dt.Columns.Add("Period", typeof(string));

       DataRow NewRow = dt.NewRow();
       NewRow[0] = TextBox1.Text;
       NewRow[1] = TextBox2.Text;
       GridView1.DataSource = dt;

here payscale,incrementamt and period are database field name.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download