gridview有问题
protected void DeleteRowButton_Click(Object sender, GridViewDeleteEventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["connectionAkaryakit"].ConnectionString);
con.Open();
int i = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value);
string str1 = "DELETE FROM dbo.Urun_Satis where Musteri_Bilgisi=" + i + "";
SqlCommand cmd = new SqlCommand(str1, con);
cmd.ExecuteNonQuery();
con.Close();
}
目录超出范围。它不应为负值,并且应小于集合的大小。 \ R \ n参数名称:索引“}
答案 0 :(得分:0)
问题出在这一行:
int i = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value);
您需要检查什么?
我说的是无键,如果e.RowIndex = 20
会怎样?这意味着: GridView1.DataKeys [20] .Value ?您是否为网格视图定义了此数量的键?