Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
any better insert row from textboxes or stright in gridview
Posted

Try this:
C#
DataTable Dt = (DataTable)(GridView1.DataSource);
 Dt.Rows.Add(Dt.NewRow());
 Dt.Rows[Dt.Rows.count-1]["ColName"]=txtProd.Text;
 Dt.Rows[Dt.Rows.count-1]["OtherColName"]=txtCatgeory.Text;
 Dt.Rows[Dt.Rows.count-1]["MyColumn"]=txtDescription.Text;
 Dt.AcceptChanges();
 
 GridView1.EditIndex = Dt.Rows.count-1;
 GridView1.DataSource = Dt;
 GridView1.DataBind();
 
Share this answer
 
If I could understand your question, you probably meant to ask, which is better choice

a) Add data in text boxes and then when user saves that data add new row to gridview.
b) Allow user to directly add rows in grid view (better known as inline editing of grid)


To answer this, the choice really depend on usage of Add/Edit functionality for a grid.
If user are only concerned in viewing the data and are rarely required to manipulate the data (add/edit) then choice 'a' is better.

Otherwise choice 'b' is better if implemented in correct way.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900