项目中遇到带图片,可能还有视频,flash的新闻内容显示,内容过长需要分页,网上搜了搜。这里我使用RadEditor编辑器手动控制分页符。
<
radE:RadEditor
ID
="RadEditor1"
runat
="server"
>
</
radE:RadEditor
>
<
script
type
="text/javascript"
language
="javascript"
src
="http://www.cnblogs.com/librarys/radEditorCustom.js"
></
script
>
在ToolFile.Xml中添加
![None.gif](/Images/OutliningIndicators/None.gif)
<
tools
name
="AllowPage"
>
<
tool
name
="Custom"
></
tool
>
</
tools
>
[radEditorCustom.js]
//
JScript 文件
RadEditorCommandList[
"
Custom
"
]
=
function
(commandName, editor, oTool)
![ExpandedBlockStart.gif](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
var oTool = "[page]";
editor.PasteHtml (oTool);
}
;
以上实现后台手动添加分页符。
分页原理:手动设置分页符,在显示新闻时候根据分页符号,把内容拆分成数组。根据page值访问数组中的元素显示
方法:
using
System;
using
System.Data;
using
System.Configuration;
using
System.Collections;
using
System.Web;
using
System.Web.Security;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.UI.WebControls.WebParts;
using
System.Web.UI.HtmlControls;
using
System.Text;
using
System.Text.RegularExpressions;
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![ExpandedBlockStart.gif](/Images/OutliningIndicators/ExpandedBlockStart.gif)
/**/
/// <summary>
/// AllowPager 的摘要说明
/// </summary>
public
class
AllowPager:System.Web.UI.Page
![ExpandedBlockStart.gif](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 分页标示符
/// </summary>
private static string pagesign = "[page]";
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 新闻内容分页
/// </summary>
/// <param name="content">新闻内容</param>
/// <param name="currentUrl">当前url</param>
/// <param name="page">当前页码</param>
/// <returns></returns>
public static string NewsContentPager(string content, string currentUrl,string page)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
string sign = "\\[page\\]";
if (content.IndexOf(pagesign) != -1)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
string[] arrContent = Regex.Split(content, sign, RegexOptions.IgnoreCase);
int pageSize = arrContent.Length;
//生成分页页码
StringBuilder sb = new StringBuilder();
sb.Append(arrContent[int.Parse(page)].ToString());
sb.Append("<div id=\"newspager\" style=\"margin:5px 0px 5px 0px;\">");
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
if (int.Parse(page) > 0)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
sb.AppendFormat("<a href=\"
{0}=
{1}\">上一页</a>", currentUrl + "&page", int.Parse(page) - 1);
}
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
for (int i = 0; i < pageSize; i++)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (i == int.Parse(page))
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
sb.AppendFormat("<span>{0}</span>", i + 1);
}
else
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
sb.AppendFormat("<a href=\"
{0}=
{1}\"><span class='newspage'>[{2}]</span></a>", currentUrl + "&page", i, i + 1);
}
}
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
if (int.Parse(page) < pageSize - 1)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
sb.AppendFormat("<a href=\"
{0}=
{1}\">下一页</a>", currentUrl + "&page", int.Parse(page) + 1);
}
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
sb.Append("</div>");
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
return sb.ToString();
}
return content;
}
}
调用:
public
void
init_Data()
![ExpandedBlockStart.gif](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
string nID = Get_nID();
int nKey = Get_nKey();
GS.Comm.List cl = new GS.Comm.List(nKey,nID);
lbTitle.Text = cl.sTitle;
lbAuthor.Text = "编辑:"+(cl.sAuthor==""?"ArtJie":cl.sAuthor);
lbDateTime.Text = "时间:"+cl.dPubDate.ToString();
lbNum.Text = "点击数:" + cl.nNum.ToString();
string content=cl.sText;
lbContent.Text = AllowPager.NewsContentPager(content, "news_show.aspx?nKey=" + nKey + "&nID=" + nID, Get_Page);
}