繁体   English   中英

使用gridview asp.net进行分页时索引超出范围

[英]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

我在这里做错了什么?

在此处输入图片说明

需要提及标记上GridViewDataKeyNames属性。 上面没有提到导致错误的原因。

有关DataKeyNames的更多信息

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM