删除gridview中的行时发生异常 [英] exception while deleting a row in gridview
本文介绍了删除gridview中的行时发生异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我从datalist中选择行时,我的Gridview3运行良好。但是,删除行时,我得到以下异常\
。
My Gridview3 works well when I select rows from datalist. However I get the following exception \
while deleting a row.
"Must be non-negative and less than the size of the collection"
我的代码:
My code:
<asp:gridview ID="GridView3" runat="server" ShowFooter="true" AutoGenerateColumns="false" OnRowDeleting="GridView3_RowDeleting" >
<Columns>
<asp:CommandField ShowDeleteButton="True" />
protected void GridView3_RowDeleting(Object sender, GridViewDeleteEventArgs e)
{
GridView3.DeleteRow((int)GridView3.DataKeys[e.RowIndex].Values[0]);
GridView3.DataBind();
}
任何人都可以指导我吗?
谢谢。
Can anyone guide me ?
Thanks.
推荐答案
您应该设置 DataKeyNames 属性。
在您的代码中,您还需要检查以确保该集合包含元素。 />
欲了解更多信息,请查看: SOF
我希望这会对你有所帮助。
You should set the DataKeyNames property.
On your code you also need to check to make sure the collection contains elements.
For more info check this : SOF
I hope this will help to you.
检查
[e.RowIndex-1]
这篇关于删除gridview中的行时发生异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文