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
关于c# - 使用 gridview asp.net 进行分页时索引超出范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15461267/