Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/264.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# 单击按钮获取行id_C#_Jquery_Webforms - Fatal编程技术网

C# 单击按钮获取行id

C# 单击按钮获取行id,c#,jquery,webforms,C#,Jquery,Webforms,我需要通过单击按钮从数据库中获取行id 这是我的c#代码: 这是一个动态GridView,在选择ddl中的项时由过程填充: <asp:GridView ID="gvKar" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" AutoGenerateColumns="False" DataKeyNames="LevelID" OnRowDataBound="gvKarakteristike_RowDataB

我需要通过单击按钮从数据库中获取行id

这是我的c#代码:

这是一个动态GridView,在选择ddl中的项时由过程填充:

<asp:GridView ID="gvKar" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" AutoGenerateColumns="False" DataKeyNames="LevelID" OnRowDataBound="gvKarakteristike_RowDataBound">
    <AlternatingRowStyle BackColor="White" />
    <Columns>
        <asp:TemplateField HeaderText="Kar">
            <ItemTemplate>
                <asp:Label ID="Kar" runat="server" Width="150px" Height="30px" Font-Names="Georgia" MyCustomAttr="foo" margin-Left="100px" Text='<%# Bind("CharName") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

<asp:Button ID="btnButton" runat="server" Text="Show"  autopostback="True"/>

当以警报的形式单击按钮时,必须从数据库中显示每一行的行id


有人能帮我吗?

我使用这样的代码为行分配一个单击处理程序:

Protected Sub Grid_RowDataBound(sender As Object, e As GridViewRowEventArgs)

    'apply click attribute to select a row 
    If e.Row.RowType = DataControlRowType.DataRow Then
        e.Row.Attributes("onclick") = ClientScript.GetPostBackClientHyperlink(sender, "Select$" & e.Row.RowIndex)
    End If

End Sub
然后,这将从datakeys集合中获取相关数据

Protected Sub Grid_RowCommand(sender As Object, e As GridViewCommandEventArgs)

    If e.CommandName = "Select" Then
        Dim LevelID As String = GridResults.DataKeys(e.CommandArgument).Item("LevelID")
        ' Do something with ID here
    End If

End Sub

为什么使用jquery标记?也许jquery可以帮助显示行id。
Protected Sub Grid_RowCommand(sender As Object, e As GridViewCommandEventArgs)

    If e.CommandName = "Select" Then
        Dim LevelID As String = GridResults.DataKeys(e.CommandArgument).Item("LevelID")
        ' Do something with ID here
    End If

End Sub