Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Gridview删除按钮_C#_Asp.net_Gridview - Fatal编程技术网

C# Gridview删除按钮

C# Gridview删除按钮,c#,asp.net,gridview,C#,Asp.net,Gridview,gridview有一个问题 protected void DeleteRowButton_Click(Object sender, GridViewDeleteEventArgs e) { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["connectionAkaryakit"].ConnectionString); con.Open();

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参数名称:index“}

问题在于这一行:

int i = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value);
你需要检查什么

  • 网格视图是否定义了数据键? 因为您正在访问网格视图的数据键集合
  • 假设正确定义了Datakeys,您真的定义了正确数量的键吗

当我说,更正键的数量时,如果
e.RowIndex=20
?这意味着:GridView1.DataKeys[20].Value?是否为网格视图定义了此数量的键???

您的问题是什么?目录超出范围。它不应该是负值,并且应该小于集合的大小。\R\n参数名称:index“}for int i=Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value);可能重复的