Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
I have a DataGridView which has 1 column. I want the user to add as many rows they need. Then when they move onto the next tab the rows are saved. At the moment the user enters the data and can move to next tab and if they go back the data is still there. However when I try to save the data when they leave the tab, the row count for the DataGridView is 0. Therefore not entering the foreach statement where I try get the cell data from.

My code for when I try to get the data is-
C#
foreach (DataRow row in gv_mullionList.Rows)
{
  //never gets this far
  //would set cell value to an object
}


Why do I need to do to get the rows?
Posted
Comments
CHill60 25-Mar-13 12:29pm    
Where are you putting the code with the foreach ? (specifically which event I mean)
Richard MacCutchan 25-Mar-13 12:37pm    
Add an event handler for the condition you wish to capture. This could be adding a row or ending the edit of a cell. In either case that is the point at which to check the content of any new cell in the grid.
rk_2010 27-Mar-13 3:23am    
You can add the user entered values into a datatable and persist the datatable in viewstate or session. Just bind gridview whenever needed.

1 solution

http://www.c-sharpcorner.com/UploadFile/ANURAGSARKAR19/saving-data-using-datagridview-and-doing-calculations/[^]Please try this link.Here when user enters all the information he can save the data after doing the entry.
 
Share this answer
 
v2

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