Asp.net paging Link Method

Source: Internet
Author: User

Copy codeThe Code is as follows:
/// <Summary>
/// Paging Link
/// </Summary>
/// <Param name = "pageSize"> </param>
/// <Param name = "recordCount"> </param>
/// <Param name = "currentPage"> </param>
/// <Param name = "prev"> number displayed before the current page </param>
/// <Param name = "next"> number displayed 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 page </a> ");
Return sb. ToString ();
}

Related Article

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.