Pagination of news content

Source: Internet
Author: User
/** // <Summary>
/// Pagination of news content
/// </Summary>
/// <Param name = "content"> news content </param>
/// <Param name = "extension"> extension (aspx, HTML...) </param>
/// <Returns> </returns>
Public String newscontentpager (string content, string extension)
{
String P = "\ [Page \]";

If (content. indexof ("[Page]")! =-1)
{
String page = request. querystring ["page"];
String [] arrcontent = RegEx. Split (content, P, regexoptions. ignorecase );
Int pagesize = arrcontent. length;

If (string. isnullorempty (page ))
Page = "0 ";


If (Int. parse (PAGE)> = pagesize)
{
Response. statuscode = 404;
Response. End ();
}



// Generate the page number
Stringbuilder sb = new stringbuilder ();
SB. append (arrcontent [Int. parse (PAGE)]. tostring ());
SB. append ("<Div id = \" newspager \ "style = \" margin: 5px 0px 5px 0px; \ "> ");

If (Int. parse (PAGE)> 0)
SB. appendformat ("<a href = \" {0 }_{ 1 }. {2} \ "> previous page </a>", request. querystring ["ID"], Int. parse (PAGE)-1, extension );

For (INT I = 0; I <pagesize; I ++)
{
If (I = int. parse (page ))
SB. appendformat ("<span> {0} </span>", I + 1 );
Else
SB. appendformat ("<a href = \" {0 }_{ 1 }. {3} \ "> {2} </a>", request. querystring ["ID"], I, I + 1, extension );
}

If (Int. parse (PAGE) <pageSize-1)
SB. appendformat ("<a href = \" {0 }_{ 1 }. {2} \ "> next page </a>", request. querystring ["ID"], Int. parse (PAGE) + 1, extension );

SB. append ("</div> ");

Return sb. tostring ();
}

Return content;

}

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.