Hi,
copy the datatable to the session, and on click of the button add a row to datatable and bind the gridview with the new datatabl;e and copy the datatable back to session.
private void binddata()
{
string connstring = @"Data Source=LENOVO-41B3F2CE\SQLEXPRESS;Initial Catalog=IMS;Integrated Security=True;Pooling=False";
string query = "SELECT * FROM ['ISB VAS Nodes$']";
SqlDataAdapter da = new SqlDataAdapter(query, connstring);
DataTable dt = new DataTable();
da.Fill(dt);
GridView1.DataSource = dt;
Session["data"] = dt;
GridView1.DataBind();
}
Button click event :
DataTable dt = ((DataTable)Sessio["data"]);
if(dt != null)
{
dt.Rows.Add("c1","c2","c3");
dt.AcceptChanges();
GridView1.DataSource = dt;
Session["data"] = dt;
GridView1.DataBind();
}
further refer below articles.
Insert a new row to gridview[
^]
Dynamically adding and deleting rows from ASP.NET GridView[
^]
hope it helps.