Asp.net gets the row number of the current row in ListView and gridview, listviewgridview
This example describes how to use asp.net to obtain the row number of the current row in ListView and gridview. We will share this with you for your reference. The details are as follows:
In aspx, a template column in The gridview/ListView is called linkbutton. When you want to click it, you can obtain the index value of the row in which it is located.
ListView:
First:
<ItemTemplate> <tr> <td> <asp:LinkButton runat="server" ID="btnSelected" Text='<%# (Container.DisplayIndex+1).ToString() %>' ></asp:LinkButton> </td> </tr></ItemTemplate>
Second:
<ItemTemplate> <li> <asp:LinkButton ID="btnDelete" runat="server" CommandName="Delete" Text="<%# Container.DataItem %>"></asp:LinkButton> </li></ItemTemplate>
In the gridview
First:
<itemtemplate> <asp:LinkButton ID="LinkButton1" runat="server"</itemtemplate>
Protected void LinkButton1_Click (object sender, EventArgs e) {// row number int row = (GridViewRow) (LinkButton) sender). NamingContainer). RowIndex ;}
Second:
<asp:GridView ID="gvTest" runat="server"> <Columns> <asp:TemplateField> <ItemTemplate> DisplayIndex : <%# Container.DisplayIndex %> || DataItemIndex : <%# Container.DataItemIndex %><br /> </ItemTemplate> </asp:TemplateField> </Columns></asp:GridView>
I hope this article will help you design your asp.net program.
Articles you may be interested in:
- Use of ListView and DropDownList in ASP. NET notes
- Use of ListView (List View) in ASP. NET to bind source code to the foreground
- Implementation Code of asp.net ListView alternate background color
- Asp.net ListView Data Binding
- Flexible use of the gridview control in asp.net
- How to Use jQuery to implement ASP. NET GridView folding and stretching
- In asp.net, the displayed message is displayed when the cursor moves the GridView data.
- How to add and delete a prompt box for the GridView in ASP. NET
- ASP. NET use the gridview to obtain the index value of the current row
- ASP. NET using the GridView to export Excel Implementation Method