asp.net长文章插入分页符^进行分页
content为显示新闻内容的label控件
lbpage为显示分页页码的label控件
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 + "页 ";
for (int i = 0; i < temp.Length; i++)
{
lbpage.Text+=("[<a href =article.aspx?id="+Request["id"].ToString()+"&page=" + i + ">" + (i+1) + "</a>] ");
}
content.Text = temp[page].ToString();
}
}
}
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 + "页 ";
for (int i = 0; i < temp.Length; i++)
{
lbpage.Text+=("[<a href =article.aspx?id="+Request["id"].ToString()+"&page=" + i + ">" + (i+1) + "</a>] ");
}
content.Text = temp[page].ToString();
}
}
}