【发布时间】:2014-02-18 07:42:24
【问题描述】:
我收到类似
的错误"索引超出范围。必须为非负数且小于大小 合集”
尝试删除 gridview 行时。我的 aspx.cs 代码如下:
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
try
{
main delete=new main();
// int id = Convert.ToInt32(GridView1.Rows[e.RowIndex].Cells["id"].Value);
// string ID = GridView1.Rows[e.RowIndex].ToString();
sQLcONN.Open();
string Query = "delete * from shoppingcart where shoppingcart.with_puja = '"+Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value.ToString())+"' ";
delete.deleteData(Query);
Bindgrid();
sQLcONN.Close();
}
catch (Exception ex)
{
Console.WriteLine("{0} Exception caught.", ex);
}
}
【问题讨论】:
-
检查e.RowIndex的值,一定是错的
-
您确实需要先对代码格式和命名进行排序。