我在3个不同的页面中有3个GridView控件。他们以前工作得很好。 突然我得到这个错误信息:Gridview:索引超出范围
无效的回发或回调参数。事件验证使用
<pages enableeventvalidation="true" />
所以我试着把<@pages enableeventvalidation="false" />
在页面中。它仍然没有工作。 我从页面删除了这个命令。然后当单击gridview中所有girdview控件的按钮时,另一条消息显示“索引超出范围”。
int id = Convert.ToInt32(myGridView.DataKeys[e.RowIndex].Value)
它看起来像在GridView找不到datakey(e.rowIndex
的价值是OK),的DataKeyNames已设置。
protected void gvItemCategory_RowDeleting(object sender, GridViewDeleteEventArgs e) {
int categoryId = Convert.ToInt32(gvItemCategory.DataKeys[e.RowIndex].Value);
CollectionCategory category = new CollectionCategory();
category.CategoryId = categoryId;
category.Delete();
ItemCateogryShowData();
}
HTML:
<asp:GridView ID="gvItemCategory" runat="server" AutoGenerateColumns="False"
OnRowCancelingEdit="gvItemCategory_RowCancelingEdit"
OnRowDeleting="gvItemCategory_RowDeleting" OnRowEditing="gvItemCategory_RowEditing"
DataKeyNames="CategoryId" OnRowUpdating="gvItemCategory_RowUpdating">
<Columns>
<asp:TemplateField HeaderText="CateogoryName">
<ItemTemplate>
<asp:Label ID="lblItemCategoryName" runat="server" Text='<%#Eval("CategoryName") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="tbItemCateogryName" runat="server" Text='<%#Eval("CategoryName") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" ButtonType="Button" />
<asp:CommandField ShowDeleteButton="True" />
</Columns>
</asp:GridView>
你是否通过javascript操作任何东西(例如,添加项目到下拉菜单)?你在回发数据绑定网格?然后索引变为-1,这将超出范围。 – 2013-03-11 11:13:26
当您尝试enableeventValidation =“false”时会发生什么。 – coder 2013-03-11 11:26:16
在页面中放入enableeventValidation =“false”后,“无效回传或回调参数”错误消息消失,我可以看到页面内容。但gridview按钮有问题 – yilee 2013-03-11 11:37:38