C# 单击按钮获取行id
我需要通过单击按钮从数据库中获取行id 这是我的c#代码: 这是一个动态GridView,在选择ddl中的项时由过程填充: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
<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