The first method is directly in the gridview template column on the ASPX page. The disadvantage is that it starts again when the second page is displayed.
<Asp: templatefield headertext = "no." insertvisible = "false">
<Itemstyle horizontalalign = "center"/>
<Headerstyle horizontalalign = "center" width = "5%"/>
<Itemtemplate>
<% #Container. dataitemindex + 1%>
</Itemtemplate>
</ASP: templatefield>
In the second method, the computation is performed during paging, so that the computation is accumulated and added down.
Another method is put in CSCodeIs similar to the second type.
<Asp: boundfield headertext = "no.">
<Itemstyle horizontalalign = "center"/>
<Headerstyle horizontalalign = "center" width = "5%"/>
</ASP: boundfield>
Protected void mygridview_rowdatabound (Object sender, gridviewroweventargs E)
{
If (E. Row. rowindex! =-1)
{
Int indexid = This. mygridview. pageindex * This. mygridview. pagesize + E. Row. rowindex + 1;
E. Row. cells [0]. Text = indexid. tostring ();
}
}
The repeater itself has the property to get the current row number,ProgramThe member binds this row number and container. itemindex can be obtained. 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, you can change the above Code to container. itemindex+ 1See the following example:
<Asp: repeater id = "repeater1" runat = "server">
<Itemtemplate>
Row number: <% #Container. itemindex+ 1 %>
</Itemtemplate>
</ASP: repeater>
You can.
< ASP: Repeater ID = "Repeater1" Runat = "Server" >
< Itemtemplate >
<% # Container. itemindex + 1 %>
<% # (Container As Repeateritem). itemindex + 1 %>
</ Itemtemplate >
</ ASP: Repeater >
Reprinted from: http://blog.163.com/wwwoop2003@126/blog/static/42004852200891654142842/