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;
}
}
}