Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/267.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/33.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,我有网格视图,其中有一个模板字段,我想通过单击按钮获取所选行的索引我无法更改字段类型,因为我想手动更改隐藏代码中的visibale属性。 这是我的密码: <asp:GridView ID="gvService" runat="server" BackColor="White" AutoGenerateColumns="False" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="

我有网格视图,其中有一个模板字段,我想通过单击按钮获取所选行的索引我无法更改字段类型,因为我想手动更改隐藏代码中的visibale属性。 这是我的密码:

    <asp:GridView ID="gvService" runat="server" BackColor="White" AutoGenerateColumns="False"
    BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Vertical" DataKeyNames="Service_Id, UserId">
    <AlternatingRowStyle BackColor="#DCDCDC" />
    <Columns>
        <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" HeaderStyle-BackColor="Gray">
            <HeaderStyle BackColor="Gray"></HeaderStyle>
        </asp:BoundField>
        <asp:BoundField DataField="L_Name" HeaderText="LastName" SortExpression="L_Name"
            HeaderStyle-BackColor="Gray">
            <HeaderStyle BackColor="Gray"></HeaderStyle>
          <asp:TemplateField>
            <ItemTemplate>
                <asp:Button ID="bttCost" runat="server" Text="Cost" OnCommand="Cmd_Pay" Visible='<%# IsNotPaid((Decimal)Eval("Cost")) %>' />
            </ItemTemplate>
          </asp:TemplateField>

要获取单击的按钮所属的行索引,请将其添加到onclick事件中

var rowIndex = ((GridViewRow)((Control)sender).NamingContainer).RowIndex;

要获取单击的按钮所属的行索引,请将其添加到onclick事件中

var rowIndex = ((GridViewRow)((Control)sender).NamingContainer).RowIndex;

我看不到按钮或模板字段我看不到按钮或模板字段