Click here to Skip to main content
15,498,859 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am creting a page,which has a gridview. I am binding a dynamic DataTable to this gridview.
for adding new row in gridview,I am using following code:
DataRow NewRow = objDT.NewRow();
 NewRow[0] = "";
 NewRow[1] = "Space";
 NewRow[2] = false;
foreach (GridViewRow GVwRow in GVwEquipFrnt.Rows)
   TextBox objTxt = (TextBox)GVwRow.FindControl("TxtWidthFrt");
   NewRow["EBBWidth"] = objTxt.Text;
ViewState["Tbl"] = objDT;

this.GVwEquipFrnt.DataSource = objDT;

problem is i am getting first row of grid is blank. I want to bind updated DataTable to gridview in same event.

Please help.

Thanks in advance.
Updated 10-Apr-12 4:35am
Muralikrishna8811 10-Apr-12 8:52am     CRLF
Hi Did you mention column names of objDT like objDT.columns.add("Column1Name"); objDT.columns.add("Column2Name");
vijay5555 10-Apr-12 8:56am     CRLF
Yes, objDT.Columns.Add(new DataColumn("EBBItem")); objDT.Columns.Add(new DataColumn("EBBEModel")); objDT.Columns.Add(new DataColumn("FLAG")); objDT.Columns.Add(new DataColumn("EBBWidth"));
Muralikrishna8811 10-Apr-12 8:59am    
firstrow in grid means head part or in item part itself
sjelen 10-Apr-12 11:25am     CRLF
I see you're using ViewState to store DataTable. But do you restore objDT from ViewState on postback? You should do that before adding new row.

1 solution

Check this answer here, seems similar problem as yours:

when am inserting 2nd record lossing previous recods any one tel me how can i see all records[^]

Share this answer

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

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