.net新闻内容分页
项目中遇到带图片,可能还有视频,flash的新闻内容显示,内容过长需要分页,网上搜了搜。这里我使用RadEditor编辑器手动控制分页符。
[radEditorCustom.js]
以上实现后台手动添加分页符。
分页原理:手动设置分页符,在显示新闻时候根据分页符号,把内容拆分成数组。根据page值访问数组中的元素显示
方法:
调用:
<radE:RadEditor ID="RadEditor1" runat="server">
</radE:RadEditor>
<script type="text/javascript" language="javascript" src="http://www.cnblogs.com/librarys/radEditorCustom.js"></script>
</radE:RadEditor>
<script type="text/javascript" language="javascript" src="http://www.cnblogs.com/librarys/radEditorCustom.js"></script>
在ToolFile.Xml中添加
<tools name="AllowPage">
<tool name="Custom"></tool>
</tools>
<tools name="AllowPage">
<tool name="Custom"></tool>
</tools>
[radEditorCustom.js]
// JScript 文件
RadEditorCommandList["Custom"] = function(commandName, editor, oTool)
{
var oTool = "[page]";
editor.PasteHtml (oTool);
};
RadEditorCommandList["Custom"] = function(commandName, editor, oTool)
{
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;
/// <summary>
/// AllowPager 的摘要说明
/// </summary>
public class AllowPager:System.Web.UI.Page
{
/// <summary>
/// 分页标示符
/// </summary>
private static string pagesign = "[page]";
/// <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)
{
string sign = "\\[page\\]";
if (content.IndexOf(pagesign) != -1)
{
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;\">");
if (int.Parse(page) > 0)
{
sb.AppendFormat("<a href=\"{0}={1}\">上一页</a>", currentUrl + "&page", int.Parse(page) - 1);
}
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}\"><span class='newspage'>[{2}]</span></a>", currentUrl + "&page", i, i + 1);
}
}
if (int.Parse(page) < pageSize - 1)
{
sb.AppendFormat("<a href=\"{0}={1}\">下一页</a>", currentUrl + "&page", int.Parse(page) + 1);
}
sb.Append("</div>");
return sb.ToString();
}
return content;
}
}
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;
/// <summary>
/// AllowPager 的摘要说明
/// </summary>
public class AllowPager:System.Web.UI.Page
{
/// <summary>
/// 分页标示符
/// </summary>
private static string pagesign = "[page]";
/// <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)
{
string sign = "\\[page\\]";
if (content.IndexOf(pagesign) != -1)
{
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;\">");
if (int.Parse(page) > 0)
{
sb.AppendFormat("<a href=\"{0}={1}\">上一页</a>", currentUrl + "&page", int.Parse(page) - 1);
}
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}\"><span class='newspage'>[{2}]</span></a>", currentUrl + "&page", i, i + 1);
}
}
if (int.Parse(page) < pageSize - 1)
{
sb.AppendFormat("<a href=\"{0}={1}\">下一页</a>", currentUrl + "&page", int.Parse(page) + 1);
}
sb.Append("</div>");
return sb.ToString();
}
return content;
}
}
调用:
public void init_Data()
{
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);
}
{
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);
}