Content pagination simple implementation code and Cheung solution (C #)

Source: Internet
Author: User
Pagination online already useful ASP to the article content pagination display code, I also did not use the time to study in detail. Published a few very long articles today, in order to facilitate the browsing of netizens, only to set the heart to write the following code. Because our program is written by C#.net, about C # Such examples, the information on the Internet can not be found; so had to start analysis from the program structure, a little program but spent half a day to complete, shame! Deficiencies, please advise, what better way to tell.

Show Content section:

Defining variables
int i,start,stop,t,stat,statt,pp,pagecount,pagesize;
Variable initial value
stat=0;
statt=0;
start=0;//the string position of the start query, initially 0
Stop=0;
pagesize=2000;//defines at least the number of strings displayed per page
pagecount=0;

Get the current number of pages
pa=request.params["Page"];
if (pa== "" | | pa==null)
Pa= "1";
Pp=convert.toint32 (PA);

Get content
articletxt=rs["Contenttxt"]. ToString ();

Determines whether the content length of a page is greater than the number of strings displayed per page defined
if (articletxt. Length>=pagesize)//If greater than the number of strings, then we can page to display
{
T=articletxt. length/pagesize;//get roughly the total number of pages
Based on the number of page loops currently available
for (i=0;i<t;i++)
{
If the query starts at a range beyond the length of the entire content, you don't have to look for breakpoints (page points);
if (start+pagesize<articletxt. Length)
{
Stat=articletxt. IndexOf ("</P>", start+pagesize)//Find </P> location of page points
if (stat<=0)//If not found
Stat=articletxt. IndexOf ("</p>", start+pagesize);//Find </p> the location of the paging point; Here you can set your own page-point judgment
}
if (stat<=0)//If the page is not found, the description can not be paged, there is no need to do other labor; otherwise, do pagination
articletext=articletxt;//the result to the variable to be exported
Else
{
stop=stat;//the location of the paging point as the end of the page
if (start+pagesize>=articletxt. Length)//If the starting position is beyond the length of the entire content, the end of the page is the end of the content
Stop=articletxt. Length;
if (pp==i+1)//If is current, then output the contents of the current page
Articletext=articletxt. Substring (Start,stop-start);//Fetch the starting position of the content to the end position this string output
start=stat;//the end position as the starting position for the next page
pagecount++;//Get actual page totals
}
}
}

Pagination section (it's much simpler here)


String html;//defines a paging code variable
if (pagecount>1)///When the number of pages is greater than 1 we show the number of pages
{
for (i=1;i<=pagecount;i++)
{
if (I==PP)//If is the current page, bold display
html+= "<b>[" +i+ "]</b>";
Else
html+= "<a href=?id=" +articleid+ "&page=" +i+ ">[" +i+ "]</a>";
}
if (Pp+1>pagecount)//shows the next page for easy browsing
html+= "<a href=?id=" +articleid+ "&page=" + (PageCount) + ">[next page]</a></p>";
Else
html+= "<a href=?id=" +articleid+ "&page=" + (pp+1) + ">[next page]</a></p>";
}

You can add the above code to try! If you have any questions, please post it to the Net People forum, address: http://bbs.wrclub.net


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.