asp.net pagination Link Method _ Practical Tips

Source: Internet
Author: User
Copy Code code as follows:

<summary>
Page links
</summary>
<param name= "PageSize" ></param>
<param name= "RecordCount" ></param>
<param name= "CurrentPage" ></param>
<param name= "prev" > The quantity shown before the current page </param>
<param name= "Next" > The quantity shown after the current page </param>
<returns></returns>
public string pagelink (int pageSize, int recordCount, int currentpage, int prev, int next)
{
int pagecount = recordCount% pageSize = 0? (recordcount/pagesize): ((int) math.ceiling ((double) recordcount/pagesize));
StringBuilder sb = new StringBuilder ();
if (CurrentPage > 1 && recordCount > 1)
{
Sb. Append ("<a href=\" "page=");
Sb. Append ((currentPage-1). ToString ());
Sb. Append ("> previous page </a>");
}
if (CurrentPage > prev + 1)
Sb. Append ("<a href=\"? page=1\) >1</a> ... ");
if (CurrentPage < prev)
Next = next + prev-currentpage + 1;
if (Next > Pagecount-currentpage)
Prev = prev + next-(pagecount-currentpage);
for (int i = 1; I <= PageCount; i++)
{
if (i = = currentpage)
{
Sb. Append ("<a href=\"? page= "+ i +" \ "class=\" current\ "><font color=\" red\ ">" + i + "</font></a>" );
}
Else
{
if (i > (currentpage-prev-1) && i < (currentpage + next + 1))
{
Sb. Append ("<a href=\" "page=" + i + ">" + i + "</a>");
}
}
}
if (CurrentPage < Pagecount-next)
Sb. Append ("... <a href=\" "page=" + pagecount.tostring () + ">" + pagecount.tostring () + "</a>");
if (CurrentPage < PageCount)
Sb. Append ("<a href=\" "page=" + (CurrentPage + 1). ToString () + "\" > Next </a> ");
Return SB. ToString ();
}

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.