How to get row data by clicking a button in a row in an ASP.NET gridview

前端 未结 7 1644
情深已故
情深已故 2020-12-09 08:56

I have a GridView in a ASP.NET web application, in which I have added two buttons in each row:

 

        
相关标签:
7条回答
  • 2020-12-09 09:25
    <ItemTemplate>
         <asp:Button ID="Button1" runat="server" Text="Button" 
                OnClick="MyButtonClick" />
    </ItemTemplate>
    

    and your method

     protected void MyButtonClick(object sender, System.EventArgs e)
    {
         //Get the button that raised the event
    Button btn = (Button)sender;
    
        //Get the row that contains this button
    GridViewRow gvr = (GridViewRow)btn.NamingContainer;
    }
    
    0 讨论(0)
提交回复
热议问题