Recently wrote a. NET paging control, put it in the garden ... You feel good, just point a praise, not good, just tell me why ....
The use of request.querystring ....
Parameters:
public int currentpageindex = 0;//current page public
int pagesize = 16;//The number of bars displayed per page public
int pagecount = 0;//pages Public
int rowscount = 0;//Total Bar number public
string prevtext = "Previous page";
public string nexttext = "Next page";
public string ellipsetext = "...";//separator public
int edgeentries = 2;//page Edge public
bool prevshowalways = true;//Previous page button is
do not show public bool nextshowalways = true;//Next page button show public
int displayentries = 5;//show several buttons public
string URL ;
public string pagestr = "";
Classes to use
Calculate the maximum number of pages there's nothing to say here, read out the data from the database and assign it to Rowscount.
Calculates the maximum number of pages public
int numpages ()
{return Convert.ToInt32 (math.ceiling (
decimal) rowscount/pagesize) );
}
The main problem is to compute the start and end buttons. Here, the whole thing's fine.
At first I was using the following code, but there was a problem .... If Displayentries is 2n-1, the last one comes out of 2n.
Calculates the start and end paging button public
int[] Getinterval ()
{
int nehalf = Convert.ToInt32 (Math.ceiling () based on the current number of pages and display numbers ( Decimal)) (DISPLAYENTRIES/2));
PageCount = NumPages ();
int upperlimit = pagecount-displayentries;//Max is upperlimit, then the number of buttons can not be guaranteed.
int start = currentpageindex > Nehalf? Math.max (Math.min (Currentpageindex-nehalf, Upperlimit), 1): 1;
int end = CurrentPageIndex > nehalf? Math.min (CurrentPageIndex + nehalf-1, PageCount): Math.min (Displayentries, PageCount);
return new int[] {start, end};
}
The main reason is that math.ceiling returns an integer, and 2n-1 and 2n return the same number, so there is a problem with the number of buttons.
So, I've made a distinction between odd and even
Calculates the start and end paging button public
int[] Getinterval ()
{
int nehalf = Convert.ToInt32 (Math.ceiling () based on the current number of pages and display numbers ( Decimal)) (DISPLAYENTRIES/2));
PageCount = NumPages ();
int upperlimit = pagecount-displayentries;
int start,end;
if (displayentries% 2 = 0)
{
start = currentpageindex > Nehalf? Math.max (Math.min (Currentpageindex-nehalf, Upperlimit), 1): 1;
}
Else
{
start = currentpageindex > Nehalf? Math.max (Math.min (currentpageindex-nehalf+1, Upperlimit), 1): 1;
}
end = CurrentPageIndex > nehalf? Math.min (CurrentPageIndex + nehalf-1, PageCount): Math.min (Displayentries, PageCount);
return new int[] {start, end};
}
Add a Button class
public string Appenditem (int PageID, string text)
{
string lnk;
int id = PageID < 1? 1: (PageID < PageCount pageid:pagecount);
if (id = = CurrentPageIndex)
{
lnk = ' <span class= ' current ' > ' + text + ' </span> ';
}
else
{
lnk = "<a href=?" + URL + "&pageid=" + ID + ">" + text + "</a>";
}
return lnk;
}