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>