[英]Index out of range when paging using gridview asp.net
int index = -1;
foreach (GridViewRow gvrow in lstHoliday.Rows)
{
index = (int)lstHoliday.DataKeys[gvrow.RowIndex].Value;
bool result = ((CheckBox)gvrow.FindControl("Selector")).Checked;
}
在这里得到一个错误:
index = (int)lstHoliday.DataKeys[gvrow.RowIndex].Value;
Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
我在这里做错了什么?
需要提及标记上GridView
的DataKeyNames
属性。 上面没有提到导致错误的原因。
有关DataKeyNames的更多信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.