// Paging class
Using system;
Using system. DaTa;
Using system. configuration;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using system. Web. UI. htmlcontrols;
Using system. text;
/// <Summary>
/// Summary of getpage
/// </Summary>
Public class getpage
{
Public getpage ()
{
}
Public static void smallbigpage (INT pagecount, int pageindex, int pagesize, out int smallpage, out int bigpage, out int count)
{
If (pagecount % pagesize) = 0)
{
Count = pagecount/pagesize;
}
Else
{
String doub = convert. tostring (pagecount/pagesize );
Count = convert. toint32 (doub. Split ('.') [0]. tostring () + 1;
// COUNT = convert. toint32 (doub );
}
If (pageindex <1)
{
Pageindex = 1;
}
If (pageindex> count)
{
Pageindex = count;
}
If (pageindex) * pagesize)> pagecount)
{
Bigpage = pagecount;
}
Else
{
Bigpage = (pageindex) * pagesize );
}
Smallpage = (pageindex-1) * pagesize );
}
Public static string getpagesize (INT pageindex, int pagecount, string URL, int pagetype)
{
Stringbuilder pageinfo = new stringbuilder ();
Pageinfo. append ("Total <font color = Red>" + pagecount + "</font> page & nbsp ;");
Switch (pagetype)
{
Case 1:
If (pageindex = 1)
{
Pageinfo. append ("homepage previous ");
}
Else
{
Pageinfo. append ("<a href = \"? Pageindex = 1 & "+ URL +" \ "> homepage </a> & nbsp ;");
Pageinfo. append ("<a href = \"? Pageindex = "+ (pageindex-1) +" & "+ URL +" \ "> previous page </a> & nbsp ;");
}
For (INT I = pageindex-4; I <= pageindex-1; I ++)
{
If (I> 0)
{
Pageinfo. append ("<a href = \"? Pageindex = "+ I +" & "+ URL +" \ "> [" + I + "] </a> & nbsp ;");
}
}
For (INT I = pageindex; I <pageindex + 4; I ++)
{
If (I <= pagecount)
{
Pageinfo. append ("<a href = \"? Pageindex = "+ I +" & "+ URL +" \ "> [" + I + "] </a> & nbsp ;");
}
}
If (pageindex <pagecount)
{
Pageinfo. append ("<a href = \"? Pageindex = "+ (pageindex + 1) +" & "+ URL +" \ "> next page </a> & nbsp ;");
}
Pageinfo. append ("<a href = \"? Pageindex = "+ pagecount +" & "+ URL +" \ "> last page </a> & nbsp ;");
Break;
Default:
Break;
}
Return pageinfo. tostring ();
}
}
// Drop page
// Statement
Protected datatable DS = new datatable ();
Protected string where;
Protected int smallpage;
Protected int bigpage;
Protected int pagesize = 20;
Protected int pageindex = 1;
Protected int count;
Protected string URL;
// Judge
If (request ["pageindex"]! = NULL)
{
Pageindex = convert. toint32 (request ["pageindex"]. tostring ());
}
DS = dbheleper. getdataset ("datatable type returned for obtaining data ");
// Pagination
Getpage. smallbigpage (Ds. Rows. Count, pageindex, pagesize, out smallpage, out bigpage, out count );
Read data cyclically
If (smallpage> = 0)
{
For (INT I = smallpage; I <bigpage; I ++)
{
Datarow rs = Ds. Rows [I];
// Display data
RS [0]. tostring ();
}
}
// Returns the string type by page.
Getpage. getpagesize (pageindex, Count, URL, 1)