Asp.net long article pagination

Source: Internet
Author: User
Public String nohtml (string htmlstring) // remove HTML tags
{
// Delete the script
Htmlstring = RegEx. Replace (htmlstring, @ "<SCRIPT [^>] *?>. *? </SCRIPT> "," ", regexoptions. ignorecase );
// Delete HTML
Htmlstring = RegEx. Replace (htmlstring, @ "<(. [^>] *)>", "", regexoptions. ignorecase );
Htmlstring = RegEx. Replace (htmlstring, @ "([\ r \ n]) [\ s] +", "", regexoptions. ignorecase );
Htmlstring = RegEx. Replace (htmlstring, @ "-->", "", regexoptions. ignorecase );
Htmlstring = RegEx. Replace (htmlstring, @ "<! --. * "," ", Regexoptions. ignorecase );

Htmlstring = RegEx. Replace (htmlstring, @ "& (quot | #34);", "\" ", regexoptions. ignorecase );
Htmlstring = RegEx. Replace (htmlstring, @ "& (Amp | #38);", "&", regexoptions. ignorecase );
Htmlstring = RegEx. Replace (htmlstring, @ "& (LT | #60);", "<", regexoptions. ignorecase );
Htmlstring = RegEx. Replace (htmlstring, @ "& (GT | #62);", ">", regexoptions. ignorecase );
Htmlstring = RegEx. Replace (htmlstring, @ "& (nbsp | #160);", "", regexoptions. ignorecase );
Htmlstring = RegEx. Replace (htmlstring, @ "& (iexcl | #161);", "\ xA1", regexoptions. ignorecase );
Htmlstring = RegEx. Replace (htmlstring, @ "& (cent | #162);", "\ xa2", regexoptions. ignorecase );
Htmlstring = RegEx. Replace (htmlstring, @ "& (pound | #163);", "\ xa3", regexoptions. ignorecase );
Htmlstring = RegEx. Replace (htmlstring, @ "& (copy | #169);", "\ xa9", regexoptions. ignorecase );
Htmlstring = RegEx. Replace (htmlstring, @ "& # (\ D +);", "", regexoptions. ignorecase );

Htmlstring. Replace ("<","");
Htmlstring. Replace ("> ","");
Htmlstring. Replace ("\ r \ n ","");
Htmlstring = httpcontext. Current. server. htmlencode (htmlstring). Trim ();

Return htmlstring;
}
Public String outputbysize (string p_strcontent) // paging Function
{
String m_strret = "";
Int m_intpagesize = 2500 ;// Article Size per page
Int m_intcurrentpage = 1; // set the first page to the initial Page.
Int m_inttotalpage = 0;
Int m_intarticlelength = nohtml (p_strcontent). length; // Article Length
If (m_intpagesize <m_intarticlelength)
{// If the size of each page is greater than the length of the article, no paging is required.
If (m_intarticlelength % m_intpagesize = 0)
{// Set total pages count
M_inttotalpage = m_intarticlelength/m_intpagesize;
}
Else
{// If the totalsize
M_inttotalpage = m_intarticlelength/m_intpagesize + 1;
}
If (request. querystring ["pages"]! = NULL)
{// Set current page number
Try
{// Handle abnormal Address Bar values
M_intcurrentpage = convert. toint32 (request. querystring ["pages"]);
If (m_intcurrentpage> m_inttotalpage)

M_intcurrentpage = m_inttotalpage;

}

Catch
{
M_intcurrentpage = m_intcurrentpage;
}
}
// Set the page content to get the size of the current page
If (m_intcurrentpage <m_inttotalpage)
{
M_intpagesize = m_intcurrentpage <m_inttotalpage? M_intpagesize: (m_intarticlelength-m_intpagesize * (m_intcurrentpage-1 ));
M_strret + = p_strcontent.substring (m_intpagesize * (m_intcurrentpage-1), m_intpagesize );
}
Else if (m_intcurrentpage = m_inttotalpage)
{
Int mm_intpagesize = m_intarticlelength-m_intpagesize * (m_intcurrentpage-1 );
M_strret + = p_strcontent.substring (m_intarticlelength-mm_intpagesize );
}

string m_strpageinfo = "

";
for (INT I = 1; I <= m_inttotalpage; I ++)
{
If (I = m_intcurrentpage)
m_strpageinfo + = "" + I + "| ";
else
m_strpageinfo + = " "+ I +" | ";
}< SPAN class = "apple-converted-space">
/ /The output page number is displayed.
This. labpagenumber. TEXT = m_strpageinfo;

}< SPAN class = "apple-converted-space">
else
{
m_strret + = p_strcontent;
}< SPAN class = "apple-converted-space">
return m_strret;
}< SPAN class = "apple-converted-space">

Protected void page_load (Object sender, eventargs E)
{
Sqldatareader DR = shuju. duquzt (int32.parse (request. querystring ["wzid"]);
If (DR = NULL) return;
If (dr. Read ())
{
This. labcontent. Text = outputbysize (Dr ["wzcontent"]. tostring (); // call this function
...

Controls used at the front-end page: <asp: Label id = "labpagenumber" font-size = "14px" runat = "server"> </ASP: Label>

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.