Click here to Skip to main content
11,929,166 members (64,627 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# DataGridView
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-
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 25-Mar-13 7:16am
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

Rate this: bad
Please Sign up or sign in to vote.

Solution 1[^]Please try this link.Here when user enters all the information he can save the data after doing the entry.

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

Advertise | Privacy | Mobile
Web03 | 2.8.151126.1 | Last Updated 27 Mar 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100