int id =Convert.ToInt32( this.GridView1.DataKeys[e.RowIndex].Values.ToString());
当我点击删除的时候我像上面这样的到GridView1的ID值
为什么报
[ArgumentOutOfRangeException: 索引超出范围。必须为非负值并小于集合大小。
的错啊!!!请大家帮我解决一下....
...全文
10812打赏收藏
GridView1报错
int id =Convert.ToInt32( this.GridView1.DataKeys[e.RowIndex].Values.ToString()); 当我点击删除的时候我像上面这样的到GridView1的ID值 为什么报 [ArgumentOutOfRangeException: 索引超出范围。必须为非负值并小于集合大小。 的错啊!!!请大家帮我解决一下....
int id =Convert.ToInt32( this.GridView1.DataKeys[e.RowIndex].Values[0].ToString())或者
int id =Convert.ToInt32( this.GridView1.DataKeys[e.RowIndex].Value.ToString())这两种方式都可以。但是前提是:在<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="id,name"在DataKeyName中添加字段名。