如何将按钮绑定到来自gridview c#asp.net中数据库的数据.数据库中的

本文关键字:数据库 c#asp net 数据 gridview 按钮 绑定 | 更新日期: 2023-09-27 18:29:04

返回一个名为RSS_Title的列值,当我点击它时。我想处理这个值的行索引。我该怎么做?

我尝试了一些代码,但它不起作用

               <asp:TemplateField>
                    <ItemTemplate>
                       <asp:LinkButton ID="LinkButton2" runat="server" onclick="LinkButton2_Click"><%#Eval("RSS_Title")%></asp:LinkButton>
                    </ItemTemplate>
               </asp:TemplateField>

如何将按钮绑定到来自gridview c#asp.net中数据库的数据.数据库中的

您可以在LinkButton2_Click事件中使用以下代码

protected void LinkButton2_Click(object sender, System.EventArgs e)
    {
        //Get the button that raised the event
        LinkButton btn = (LinkButton )sender;
        //Get the row that contains this button
        GridViewRow gvr = (GridViewRow)btn.NamingContainer;
        //Get rowindex
        int rowindex = gvr.RowIndex;
    }