Implementation of Automatic Paging for long content in Asp.net
Source: Internet
Author: User
Implementation of Automatic Paging for long content in Asp.net
When an article is too long, you can automatically write a small program to paging it.
Code: public class T3: system. Web. UI. Page
{
Private string STR; // character
Private int strl; // The total length of a character.
Private int pagesize; // The number of characters displayed on each page
Private void page_load (Object sender, system. eventargs E)
{
// Place user code here to initialize the page
STR = "1234567891234567898522555 ";
Pagesize = 3;
Strl = Str. length;
Response. Write (strl );
Substr ();
}
Private void substr ()
{
Int Ct = int32.parse (request. querystring ["page"]);
If (strl = (strl/pagesize) * pagesize) // check whether the total number of records on the page can be divisible by the number of records on each page
{
For (INT I = 1; I <= strl/pagesize; I ++)
{
Response. Write ("Page: <a href = '#' +"> "+ (I) +" </"+" A> ");
}
String S = Str. substring (pagesize * CT-pagesize, pagesize );
Response. Write (s );
}
Else if (CT * pagesize> strl) // the setting of the last page without division, for example, the character length is 13, and each page is 3, processing the display of the last page
{
For (INT I = 1; I <= (strl/pagesize) + 1; I ++)
{
Response. Write ("Page: <a href = '#'/" + "A> ");
}
String S = Str. substring (CT-1) * pagesize, strl-(CT-1) * pagesize );
Response. Write (s );
}
Else // display settings for other pages without being divisible
{
For (INT I = 1; I <= strl/pagesize + 1; I ++)
{
Response. Write ("Page: <a href = '#' +"> "+ (I) +" </"+" A> ");
}
String S = Str. substring (pagesize * CT-pagesize, pagesize );
Response. Write (s );
}
}
}
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