Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/276.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/asp.net/32.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# 如何在网格外侧的btn单击上获取行索引_C#_Asp.net_Gridview - Fatal编程技术网

C# 如何在网格外侧的btn单击上获取行索引

C# 如何在网格外侧的btn单击上获取行索引,c#,asp.net,gridview,C#,Asp.net,Gridview,我在GridView中有一个按钮。我想在点击按钮时获取行索引。如何得到它 我曾经 GridViewRow row = ((Button)sender).Parent.Parent as GridViewRow; 但是它不起作用。如果GridView中的按钮是另一个容器(可能是窗体或面板),而不是GridView 首先,您需要对GridView的引用。如果你有一个包含这个引用的变量,你应该使用它。如果没有变量,则应搜索GridView: GridView grd = this.FindCont

我在GridView中有一个按钮。我想在点击按钮时获取行索引。如何得到它

我曾经

GridViewRow row = ((Button)sender).Parent.Parent as GridViewRow;

但是它不起作用。

如果GridView中的按钮是另一个容器(可能是窗体或面板),而不是GridView

  • 首先,您需要对GridView的引用。如果你有一个包含这个引用的变量,你应该使用它。如果没有变量,则应搜索GridView:

    GridView grd = this.FindControl("GridViewName");
    
  • 之后,您可以获得GridViewRow:

    GridViewRow row = grd.SelectedRow;
    

如果按钮位于
网格视图之外
行索引的意义是什么您应该详细说明问题。