Implementing news pagination with ASP.net

Source: Internet
Author: User
Asp.net| Page idea: When adding news in the background, it is estimated that a tag should be inserted where the page should be paginated (I inserted [page]) and when shown in the foreground, I pass in a parameter page that indicates the page to display, and in the Display page, I follow the tag [page] Put the news content into the array separately, if the value of the passed parameter page is 1, I will take the value of arr[0], if it is the second ...
Also, I put the pagination of the HTML code is based on the statistics [page] to determine whether to display

Baseinfo is the basic information class that I define:

public class Baseinfo
? {
?? public string id,summary,content,picture;
?? Public DateTime Publictime;

?? Public StringBuilder pagefoot = new StringBuilder ();

?? Public Baseinfo ()
?? {?
???
??}

?? Add to
?? public int Add ()
?? {
??? ...??
??}

?? Update
?? public int Update ()
?? {
??? ...
??}
??
?? Class
?? public void Init ()
?? {
??? ...
??}
?}


In this page to pass in two parameter page and ID, the first link to this page should be 1, and must be 1,id is

The ID of the news, such as news id=1 connection should be baseinfodetail.aspx? Page=1&id=1
Nextat is the position of the next [page], Backat is the position of the previous [page] flag, Pagefoot is an HTML table I added

Runat=server
The code is as follows:
Part of the code for Baseinfodetail.aspx is as follows:
Baseinfo info = new Baseinfo ();??
???? Info.id = request.querystring["ID"];?
???? Info. Init ();

????

//******************************************************************************************

**********
???? Paging
???? I: Calculate the number of flags "[PAGE]"
???? //
???? //???????????????? --? Dream van? August 14, 2004 19:32
???? int nextat = -4,i=0,backat = 0;
???? string[] tempcontent = new STRING[20];
???? Todo
???? {
????? Nextat + 4;
????? Nextat = info. Content.indexof ("[PAGE]", nextat);??

????????????

?
????? if (Nextat!=-1)
????? {
?????? i++;
?????? Tempcontent[i] = info. Content.substring

(Backat,math.abs (Nextat-backat));
?????? Backat = Nextat + 6;
?????}
????} while (Nextat!=-1);
??????
???? int currentpage = Convert.ToInt32 (request.querystring

["Page"]);
???? if (i>0)
???? {
????? Info. Content = Tempcontent[currentpage];
????? This. Pagefoot.visible = true;
????}
???? Else
????? This. Pagefoot.visible = false;
?????
???? Info. Pagefoot.append ("Total" +i.tostring () + "page");
???? for (int j=1;j<=i;j++)
???? {
????? Info. Pagefoot.append ("[

Href= ' baseinfodetail.aspx? Page= "+j.tostring () +" &id= "+info.id+" ' > "+j.tostring () +"]

");
????}
???? if (currentpage!= i)
???? {
????? CurrentPage + 1;
????? Info. Pagefoot.append ("next page");
????}
????
????

//******************************************************************************************

**********





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.