asp.net

位置:IT落伍者 >> asp.net >> 浏览文章

ASP.NET长文章分页显示函数


发布日期:2019年06月13日
 
ASP.NET长文章分页显示函数

public string NoHTML(string Htmlstring) //去除HTML标记

{

//删除脚本

Htmlstring = RegexReplace(Htmlstring @ <script[^>]*?>*? </script> RegexOptionsIgnoreCase);

//删除HTML

Htmlstring = RegexReplace(Htmlstring @ <([^>]*)> RegexOptionsIgnoreCase);

Htmlstring = RegexReplace(Htmlstring @([\r\n])[\s]+ RegexOptionsIgnoreCase);

Htmlstring = RegexReplace(Htmlstring @> RegexOptionsIgnoreCase);

Htmlstring = RegexReplace(Htmlstring @ <!* RegexOptionsIgnoreCase);

Htmlstring = RegexReplace(Htmlstring @&(quot|#); \ RegexOptionsIgnoreCase);

Htmlstring = RegexReplace(Htmlstring @&(amp|#); & RegexOptionsIgnoreCase);

Htmlstring = RegexReplace(Htmlstring @&(lt|#); < RegexOptionsIgnoreCase);

Htmlstring = RegexReplace(Htmlstring @&(gt|#); > RegexOptionsIgnoreCase);

Htmlstring = RegexReplace(Htmlstring @&(nbsp|#); RegexOptionsIgnoreCase);

Htmlstring = RegexReplace(Htmlstring @&(iexcl|#); \xa RegexOptionsIgnoreCase);

Htmlstring = RegexReplace(Htmlstring @&(cent|#); \xa RegexOptionsIgnoreCase);

Htmlstring = RegexReplace(Htmlstring @&(pound|#); \xa RegexOptionsIgnoreCase);

Htmlstring = RegexReplace(Htmlstring @&(copy|#); \xa RegexOptionsIgnoreCase);

Htmlstring = RegexReplace(Htmlstring @&#(\d+); RegexOptionsIgnoreCase);

HtmlstringReplace( < );

HtmlstringReplace(> );

HtmlstringReplace(\r\n );

Htmlstring = HttpContextCurrentServerHtmlEncode(Htmlstring)Trim();

return Htmlstring;

}

public string OutputBySize(string p_strContent)//分页函数

{

string m_strRet = ;

int m_intPageSize = ;//文章每页大小

int m_intCurrentPage = ;//设置第一页为初始页

int m_intTotalPage = ;

int m_intArticlelength = NoHTML(p_strContent)Length;//文章长度

if (m_intPageSize < m_intArticlelength)

{//如果每页大小大于文章长度时就不用分页了

if (m_intArticlelength % m_intPageSize == )

{//set total pages count

m_intTotalPage = m_intArticlelength / m_intPageSize;

}

else

{//if the totalsize

m_intTotalPage = m_intArticlelength / m_intPageSize + ;

}

if (RequestQueryString[pages] != null)

{//set Current page number

try

{//处理不正常的地址栏的值

m_intCurrentPage = ConvertToInt(RequestQueryString[pages]);

if (m_intCurrentPage > m_intTotalPage)

m_intCurrentPage = m_intTotalPage;

}

catch

{

m_intCurrentPage = m_intCurrentPage;

}

}

//set the page content 设置获取当前页的大小

if (m_intCurrentPage < m_intTotalPage)

{

m_intPageSize = m_intCurrentPage < m_intTotalPage ? m_intPageSize : (m_intArticlelength m_intPageSize * (m_intCurrentPage ));

m_strRet += p_strContentSubstring(m_intPageSize * (m_intCurrentPage ) m_intPageSize);

}

else if(m_intCurrentPage == m_intTotalPage )

{

int mm_intPageSize=m_intArticlelength m_intPageSize * (m_intCurrentPage );

m_strRet += p_strContentSubstring(m_intArticlelength mm_intPageSize);

}

string m_strPageInfo = <p> </p>;

for (int i = ; i <= m_intTotalPage; i++)

{

if (i == m_intCurrentPage)

m_strPageInfo += + i + 页 | ;

else

m_strPageInfo += <a  + RequestQueryString[wzid] + _pages + i + l> + i + </a>|;

}

//输出显示各个页码

thislabPageNumberText = m_strPageInfo;

}

else

{

m_strRet += p_strContent;

}

return m_strRet;

}

protected void Page_Load(object sender EventArgs e)

{

SqlDataReader dr = shujuduquzt(IntParse(RequestQueryString[wzid]));

if (dr == null) return;

if (drRead())

{

thislabContentText = OutputBySize(dr[wzcontent]ToString());//调用该函数

前台页面分页处使用的控件 <asp:Label ID=labPageNumber FontSize=px runat=server> </asp:Label>

               

上一篇:如何制作Asp.Net界面模板

下一篇:ASP.NET 2.0 Master Page主题以及皮肤的使用