Click here to Skip to main content
15,889,335 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I have a foreach loop that always is returning a count that is less by 1.

I have used this type of a loop numerous times but it the first time I have seen this error and cannot seem to get around it.

Here is my code:
C#
foreach (Gridview row in gridview1.rows)
{
//DO SOME WORK HERE
}


when I hover over gridview1.rows in debug mode it always has 1 row less. I expect 10 rows but the count is 9.

if anyone has any resolutions or idea please let me know.

thanks
Posted
Updated 11-Jan-15 20:07pm
v2

The debugger has the correct answer, if you expect something else then you should reevaluate your code to see if you have made mistakes.
 
Share this answer
 
Hi ,
Check this
C#
foreach (GridViewRow row in gridview1.Rows)
{
    if (((CheckBox)row.FindControl("chkboxid")).Checked)
   {
    //read the label            
   }     
}


Best Regards
M.Mitwalli
 
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