asp.net长文章插入分页符^进行分页

content为显示新闻内容的label控件
lbpage为显示分页页码的label控件

ContractedBlock.gif ExpandedBlockStart.gif Code

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class article : System.Web.UI.Page
{
    
protected void Page_Load(object sender, EventArgs e)
    {
        
if (!Page.IsPostBack)
        {
            pub Pub
=new pub();
            
int id=Convert.ToInt32( Request.QueryString["id"]);
            
int page = Convert.ToInt32(Request.QueryString["page"]);
            
string sql="select * from [article] where id="+id;
            DataTable dt 
= Pub.getDt(sql);
         
string neirong = dt.Rows[0]["content"].ToString();
            
this.Page.Title = dt.Rows[0]["title"].ToString();
            
this.lbtitle.Text = dt.Rows[0]["title"].ToString(); 
            GetNews(neirong,page);

            
string sql_class = "select classname from [class] where id in(select Article.class_id from Article where id="+id+")";
            DataTable dt_class 
= Pub.getDt(sql_class);
            
this.class_name.Text= dt_class.Rows[0]["classname"].ToString();

        }
    }
    
/// <summary>
    
/// 
    
/// </summary>
    
/// <param name="strNews">新闻内容</param>
    
/// <param name="page">页码参数</param>
    protected void GetNews(string strNews, int page)
    {
        
string[] temp = strNews.Split('^'); //取的分页符

        
if (temp.Length <= 1)
        {
            content.Text 
= strNews; //文章内容
        }
        
else
        {

            lbpage.Text 
= "" + temp.Length + "页&nbsp;&nbsp;";
            
for (int i = 0; i < temp.Length; i++)
            {
                lbpage.Text
+=("[<a href =article.aspx?id="+Request["id"].ToString()+"&page=" + i + ">" + (i+1+ "</a>]&nbsp;&nbsp;");
            }
            content.Text 
= temp[page].ToString();
        }

    }


}

转载于:https://www.cnblogs.com/honghu3000/archive/2008/12/21/1359354.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值