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

标签 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

最佳答案

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

更多关于 DataKeyNames

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

相关文章:

c# - .pem 文件和 .p12 文件和 URL - 天啊

c# - 使用 LINQ to SQL 的条件投影

c# - 在 .ASPX 文件中使用 Eval()

gridview - 如何在 Yii2 gridview 中连接两个表并获取值

C# Gridview 标题样式不适用于排序

Android SQLite修改后刷新 View 数据

c# - ASP.NET GridView 第二个标题行跨越主标题行

C# - 进程没有终止

c# - 具有客户端证书和基本身份验证的 WCF 客户端

c# - CrossGeolocator 的 GetPositionAsync 不起作用