C # display page number

Source: Internet
Author: User

The current page number is automatically displayed. You can also customize classification links.Code

Using system;

Namespace bookshopcn. Service
{
/// <Summary>
/// Summary of the page.
/// </Summary>
Public class Pager
{
Public Pager (){}

Protected static int _ buttoncount = 11;
Protected static string _ nextpage = "<a href = {0}> next page </a> ";
Protected static string _ linkurl = "? Page = {0 }";
Protected static string _ lastpage = "<a href = {0}> previous page </a> ";

/// <Summary>
/// Next page
/// </Summary>
Public static string nextpage
{
Get {return _ nextpage ;}
Set {_ nextpage = value ;}
}

/// <Summary>
/// Previous Page Link
/// </Summary>
Public static string lastpage
{
Get {return _ lastpage ;}
Set {_ lastpage = value ;}
}

/// <Summary>
/// Format when set
/// </Summary>
Public static string nextpagetext
{
Get {return _ nextpage ;}
Set {_ nextpage = value ;}
}

/// <Summary>
/// Display the total number of buttons
/// </Summary>
Public static int bottoncount
{
Get {return _ buttoncount ;}
Set {_ buttoncount = value ;}
}
/// <Summary>
/// Return the page information
/// </Summary>
/// <Param name = "_ recordcount"> total number of records </param>
/// <Param name = "_ pagesize"> page length </param>
/// <Param name = "_ pageindex"> current page </param>
/// <Returns> </returns>
Public static string pageinfo (INT _ recordcount, int _ pagesize, int _ pageindex, string link)
{
String firstpage = string. Format ("<a href =" + link + "> [homepage] </a>", "1 ");
String pageinfo = "total page {0}/current page {1}" + firstpage;
String pagenext = "<a href =" + link + "> <B> {0} </B> </a> ";
Int pagecount = _ recordcount/_ pagesize; // total number of pages
Pagecount = pagecount <= 0? 1: pagecount;
Pageinfo = string. Format (pageinfo, pagecount. tostring (), _ pageindex. tostring ());
String lastpage = string. Format ("<a href =" + link + "> [last page] </a>", pagecount );

Int n = _ buttoncount/2; // displays the number of left and right sides
Int startpage = _ pageindex-N;
Int endpage = _ pageindex + N;
_ Lastpage = string. Format (_ lastpage, link); // Previous Page
_ Lastpage = _ PageIndex-1> 1? String. Format (_ lastpage, (_ PageIndex-1). tostring (): String. Format (_ nextpage, "1 ");

_ Nextpage = string. Format (_ nextpage, link); // next page
_ Nextpage = _ pageindex + 1 <= pagecount? String. Format (_ nextpage, _ pageindex. tostring (): String. Format (_ nextpage, pagecount. tostring ());

If (endpage> pagecount)
{
Startpage = (_ pageindex-N)-(endpage-pagecount );
Endpage = pagecount;
}
If (startpage <1)
{
Endpage = _ buttoncount;
Startpage = 1;
}

For (INT I = startpage; I <= endpage; I ++)
{
If (I! = _ Pageindex)
Pageinfo + = string. Format (pagenext, I );
Else
Pageinfo + = "<B>" + I. tostring () + "</B> ";
}
Pageinfo + = lastpage;
Return pageinfo;
}
}
}

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.