gridview中的Foreach循环返回的计数减少了1 [英] Foreach loop in gridview returns count that is 1 less

查看:63
本文介绍了gridview中的Foreach循环返回的计数减少了1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个foreach循环,总是返回少于1的计数。



我已经多次使用过这种类型的循环,但是我第一次看到这个错误并且似乎无法绕过它。



这是我的代码:

  foreach (Gridview row  in  gridview1.rows)
{
// 在这做一些工作
}





当我在调试模式下将鼠标悬停在gridview1.rows上时,它总是少一行。我希望10排,但计数是9.



如果有人有任何决议或想法请告诉我。



谢谢

解决方案

调试器有正确的答案,如果你期待别的话,你应该重新评估你的代码,看看你是否犯了错误。




查看此

<前lang =cs> foreach (GridViewRow row in gridview1.Rows)
{
if (( (CheckBox)row.FindControl( chkboxid))。已检查)
{
// 阅读标签
}
}





最好的问候

M.Mitwalli


我已经解决了问题:)那里曾经有些代码改了一些时间回来影响了这段代码,导致它数量减少1.



感谢您的帮助,但


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:

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

解决方案

The debugger has the correct answer, if you expect something else then you should reevaluate your code to see if you have made mistakes.


Hi ,
Check this

foreach (GridViewRow row in gridview1.Rows)
{
    if (((CheckBox)row.FindControl("chkboxid")).Checked)
   {
    //read the label            
   }     
}



Best Regards
M.Mitwalli


I have resolved the issue :) there had been some code changed some time back that affected this piece of code causing it to count less 1.

thanks for the help though


这篇关于gridview中的Foreach循环返回的计数减少了1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆