Solution: How to Inserting new record in GridView without database in ASP.NET 2.0 |
|
Answered By
Moderator1
on
2/15/2010 8:44:59 PM |
|
|
|
|
Hi,
With the help of DataTable and ViewState variable, you can do this. I've sample code for you. Place a GridView control and "Add New" Button. In the Click event of the "Add New" button, place the below code.
DataTable dt;
if (ViewState["Dt"] == null)
{
dt = new DataTable();
dt.Columns.Add("Col1");
dt.Columns.Add("Col2");
dt.Columns[0].DefaultValue = "Column1";
dt.Columns[1].DefaultValue = "Column2";
}
else
{
dt = (DataTable)ViewState["Dt"];
}
DataRow dr = dt.NewRow();
dt.Rows.Add(dr);
ViewState["Dt"] = dt;
GridView1.DataSource = dt;
GridView1.DataBind();
The above is simple logic. Explore it to your requirement. Good Luck. |
|
|
|