我收到錯誤,如指數超出範圍的異常,而從GridView控件
「索引超出範圍。必須大於尺寸的集合 非負少」
當試圖刪除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的值,它必須是錯的 – Cris
您確實需要先排序代碼格式和命名。 – nik0lias