.net新闻内容分页

项目中遇到带图片,可能还有视频,flash的新闻内容显示,内容过长需要分页,网上搜了搜。这里我使用RadEditor编辑器手动控制分页符。
None.gif < radE:RadEditor  ID ="RadEditor1"  runat ="server" >
None.gif                     
</ radE:RadEditor >
None.gif                     
< script  type ="text/javascript"  language ="javascript"  src ="http://www.cnblogs.com/librarys/radEditorCustom.js" ></ script >

None.gif 在ToolFile.Xml中添加
None.gif
None.gif  
< tools  name ="AllowPage" >
None.gif    
< tool  name ="Custom" ></ tool >
None.gif  
</ tools >

[radEditorCustom.js]
None.gif //  JScript 文件
None.gif

None.gifRadEditorCommandList[
" Custom " =   function (commandName, editor, oTool)
ExpandedBlockStart.gifContractedBlock.gif                
dot.gif {
InBlock.gif                    
var oTool = "[page]";
InBlock.gif                    editor.PasteHtml (oTool);
ExpandedBlockEnd.gif                }
;

以上实现后台手动添加分页符。

分页原理:手动设置分页符,在显示新闻时候根据分页符号,把内容拆分成数组。根据page值访问数组中的元素显示
方法:
None.gif using  System;
None.gif
using  System.Data;
None.gif
using  System.Configuration;
None.gif
using  System.Collections;
None.gif
using  System.Web;
None.gif
using  System.Web.Security;
None.gif
using  System.Web.UI;
None.gif
using  System.Web.UI.WebControls;
None.gif
using  System.Web.UI.WebControls.WebParts;
None.gif
using  System.Web.UI.HtmlControls;
None.gif
using  System.Text;
None.gif
using  System.Text.RegularExpressions;
None.gif
None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /// <summary>
InBlock.gif
/// AllowPager 的摘要说明
ExpandedBlockEnd.gif
/// </summary>

None.gif public   class  AllowPager:System.Web.UI.Page
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// 分页标示符
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    private static string pagesign = "[page]";
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// 新闻内容分页
InBlock.gif    
/// </summary>
InBlock.gif    
/// <param name="content">新闻内容</param>
InBlock.gif    
/// <param name="currentUrl">当前url</param>
InBlock.gif    
/// <param name="page">当前页码</param>
ExpandedSubBlockEnd.gif    
/// <returns></returns>

InBlock.gif    public static string NewsContentPager(string content, string currentUrl,string page)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
string sign = "\\[page\\]";
InBlock.gif        
if (content.IndexOf(pagesign) != -1)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
string[] arrContent = Regex.Split(content, sign, RegexOptions.IgnoreCase);
InBlock.gif            
int pageSize = arrContent.Length;
InBlock.gif            
//生成分页页码
InBlock.gif
            StringBuilder sb = new StringBuilder();
InBlock.gif            sb.Append(arrContent[
int.Parse(page)].ToString());
InBlock.gif            sb.Append(
"<div id=\"newspager\" style=\"margin:5px 0px 5px 0px;\">");
InBlock.gif
InBlock.gif            
if (int.Parse(page) > 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif                sb.AppendFormat(
"<a href=\"dot.gif{0}=dot.gif{1}\">上一页</a>", currentUrl + "&page"int.Parse(page) - 1);
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
for (int i = 0; i < pageSize; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (i == int.Parse(page))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    sb.AppendFormat(
"<span>{0}</span>", i + 1);
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif                    sb.AppendFormat(
"<a href=\"dot.gif{0}=dot.gif{1}\"><span class='newspage'>[{2}]</span></a>", currentUrl + "&page", i, i + 1);
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
if (int.Parse(page) < pageSize - 1)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif                sb.AppendFormat(
"<a href=\"dot.gif{0}=dot.gif{1}\">下一页</a>", currentUrl + "&page"int.Parse(page) + 1);
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            sb.Append(
"</div>");
InBlock.gif
InBlock.gif            
return sb.ToString();
ExpandedSubBlockEnd.gif        }

InBlock.gif        
return content;
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

调用:
None.gif public   void  init_Data()
ExpandedBlockStart.gifContractedBlock.gif    
dot.gif {
InBlock.gif        
string nID = Get_nID();
InBlock.gif        
int nKey = Get_nKey();
InBlock.gif        GS.Comm.List cl 
= new GS.Comm.List(nKey,nID);
InBlock.gif        lbTitle.Text 
= cl.sTitle;
InBlock.gif        lbAuthor.Text 
= "编辑:"+(cl.sAuthor==""?"ArtJie":cl.sAuthor);
InBlock.gif        lbDateTime.Text 
= "时间:"+cl.dPubDate.ToString();
InBlock.gif        lbNum.Text 
= "点击数:" + cl.nNum.ToString();
InBlock.gif        
string content=cl.sText;
InBlock.gif        lbContent.Text 
= AllowPager.NewsContentPager(content, "news_show.aspx?nKey=" + nKey + "&nID=" + nID, Get_Page);
ExpandedBlockEnd.gif    }

转载于:https://www.cnblogs.com/jinweida/archive/2008/07/08/1238142.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值