Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.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# 如何从asp.net gridview行获取所选行索引_C#_Asp.net_Webforms - Fatal编程技术网

C# 如何从asp.net gridview行获取所选行索引

C# 如何从asp.net gridview行获取所选行索引,c#,asp.net,webforms,C#,Asp.net,Webforms,我有一个没有数据键的gridview。单击“行编辑”按钮时,我将使用行编辑方法。我尝试了几种方法来获取行索引,但没有成功 protected void gvwCustomerLocation_RowEditing(object sender, GridViewEditEventArgs e) { var index1 = e.NewEditIndex; //gives me an incorrect index number //The Selec

我有一个没有数据键的gridview。单击“行编辑”按钮时,我将使用行编辑方法。我尝试了几种方法来获取行索引,但没有成功

   protected void gvwCustomerLocation_RowEditing(object sender, GridViewEditEventArgs e)
   {
        var index1 = e.NewEditIndex;  //gives me an incorrect index number

        //The SelectedIndex always equals -1
        for (int i = 0; i < gvwCustomerLocation.Rows.Count; i++)
        {
            if (gvwCustomerLocation.SelectedIndex == 1)
            {

            }
        }

        int index = gvwCustomerLocation.EditIndex;  //The EditIndex = -1

        GridViewRow row = gvwCustomerLocation.SelectedRow;  //The SelectedRow = null
        var test = row.RowIndex.ToString();
   }
受保护的void gvwCustomerLocation\u行编辑(对象发送方,GridViewEditEventArgs e)
{
var index1=e.NewEditIndex;//给了我一个不正确的索引号
//SelectedIndex始终等于-1
对于(int i=0;i

如何获取选定的行索引?

我最终放弃了从gridview获取行索引,决定在sql server结果集中创建一个主键,用作前端的键

您应该能够使用和
gvwCustomerLocation.Rows[e.neweditinex]
来获取所选行。@DaveAnderson不幸的是,它没有。当我单击gridview中的第一行时,index1的值是2而不是0。gridview数据绑定的是什么?当您使用
gvwCustomerLocation.Rows[e.NewEditIndex]
?@DaveAnderson时,行中的数据绑定到数据集表。您的数据集有多少行?如果
e.NewEditIndex=2
它是数据集中的哪一行?您是如何连接事件处理程序的?