Automatic gridview serial number

Source: Internet
Author: User
The first method is directly in the gridview template column on the ASPX page. this disadvantage is that it is restarted 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. <asp: templatefield headertext = "no." insertvisible = "false">
<Itemstyle horizontalalign = "center"/>
<Headerstyle horizontalalign = "center" width = "5%"/>
<Itemtemplate>
<Asp: Label id = "label2" runat = "server" text = '<% # This. mylistgridview. pageindex * This. mylistgridview. pagesize + this. mylistgridview. rows. count + 1%> '/>
</Itemtemplate>
</ASP: templatefield>

Another method is put in CS code, which is similar to the second method. <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 ();
}
}

They all work in the same way. There are many ways to achieve the same effect. In fact, they can also be implemented when reading data.
In order to avoid too many words and cause inconvenience to reading, the SQL method is put in the following link: it is actually a very simple entry level, but sometimes it is easy to forget.
Method of Automatic serial number in SQL Server (http://www.cnblogs.com/cnaspnet/articles/680609.html)

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.