AspdotnetCodes.com
Search
Articles
Books
Resources
Asp.Net News
Downloads
Free Tech Magazines
Asp.Net Web Hosting
Archives
Softwares
Newsletter
Suggest Us
Link to Us
Feeds Subscription
Articles
Questions & Answers
Tips & Tricks
 How to Inserting new record in GridView without database in ASP.NET 2.0
Posted by Pramod on  2/15/2010 6:51:19 AM Category: Asp.Net 2.0
Add to my favorites
Email to friend
How to Inserting new record in GridView without database in ASP.NET 2.0

Post Your Reply Post New Question

 Viewer's Reply
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.
 
Post Your Reply If you still have problem, post it again under this reply for better response.

 
Sponsored by
FierceDeveloper
The ASP.NET 2.0 Anthology: 101 Essential Tips, Tricks & Hacks - Free 156 Page Preview
No Nonsense XML Web Development With PHP - Free 146 Page Preview!