How to display row numbers at the front end of repeater and gridview)

Source: Internet
Author: User
How to display row numbers at the front end of repeater and gridview

To obtain the current row number of a repeater, the repeater itself has the attribute for obtaining the current row number, instead of havingProgramThe member binds the row number. How can this problem be achieved?

 

You can use container. itemindex in repeater to obtain it. See the following example:

<Asp: repeater id = "repeater1" runat = "server">
   <Itemtemplate>
       Row number:<% #Container.Itemindex%>
   </Itemtemplate>
</ASP: repeater>

If in the preceding example, the repeater has already bound data and the data is at least one record, the row number is displayed, starting from scratch. If you want to change it to start from 1, then the aboveCodeChange to container. itemindex.+ 1See the following example:

<Asp: repeater id = "repeater1" runat = "server">
   <Itemtemplate>
       Row number:<% # Container. itemindex+ 1%>
   </Itemtemplate>
</ASP: repeater>

You can.

 

What about girdview?

<Asp: gridview id = "gridview2" runat = "server">



>

                       <% #Container. dataitemindex %>
                    </Itemtemplate>

       </ASP: templatefield>

      </Columns>

<Asp: gridview>

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.