Asp.net gets the row number of the current row in ListView and gridview, listviewgridview

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.