Click here to Skip to main content
15,568,460 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.
e.g:
for adding new row in gridview,I am using following code:
C#
DataRow NewRow = objDT.NewRow();
 NewRow[0] = "";
 NewRow[1] = "Space";
 NewRow[2] = false;
 objDT.Rows.Add(NewRow);
foreach (GridViewRow GVwRow in GVwEquipFrnt.Rows)
 {
   TextBox objTxt = (TextBox)GVwRow.FindControl("TxtWidthFrt");
   NewRow["EBBWidth"] = objTxt.Text;
 }
objDT.GetChanges(DataRowState.Added);
ViewState["Tbl"] = objDT;

this.GVwEquipFrnt.DataSource = objDT;
this.GVwEquipFrnt.DataBind();


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.
Posted
Updated 10-Apr-12 4:35am
v2
Comments
Muralikrishna8811 10-Apr-12 8:52am    
Hi
Did you mention column names of objDT

like
objDT.columns.add("Column1Name");
objDT.columns.add("Column2Name");
vijay5555 10-Apr-12 8:56am    
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    
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[^]


Cheers
 
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