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

时间:2013-03-17 13:28:53

标签: c# gridview

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

我在这里做错了什么?

enter image description here

1 个答案:

答案 0 :(得分:1)

需要提及标记上DataKeyNames的{​​{1}}属性。上面没有提到它导致错误。

更多关于DataKeyNames