2
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

我在这里做错了什么?

在此处输入图像描述

4

1 回答 1

1

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

更多关于DataKeyNames

于 2013-03-17T13:47:03.257 回答