Small Data Paging

Source: Internet
Author: User

 

// 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)

 

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.