How to I add a new datarow to a datatable in ASP.Net in ASP::Button control code...

mallan

New member
...behind code? In form load event it works fine. But, when I attempt to add a datarow to a datatable then bind it to a grid it just overwrites the last row of the table instead of adding one.
Here is the code:
protected void Button1_Click(object sender, EventArgs e)
{
dataTable1.Rows.Add(dataTable1.NewRow());
a = dataTable1.Rows.Count - 1;
dataTable1.Rows[a][0] = a.ToString();
dataTable1.Rows[a][1] = a.ToString();
dataTable1.Rows[a][2] = a.ToString();
dataTable1.Rows[a][3] = a.ToString();
GridView1.DataBind();
}
 
Back
Top