[急]怎么让文章内容分页?
一篇文章内容长了,有什么办法分页?
环境: vs2005 +access 数据库 ?
[解决办法]
www.16sw.com
本站有分页实例,实例上面还有上传文章等之类的,源程序公开,欢迎下载
[解决办法]
一般WEB编辑都有插入分页标记的按钮,通过分页标记拆分新闻内容放在数组中,然后调用数组下标设置分页。我的代码如下,供参考!!
private News news=new News();
private NewsHdl newshdl=new NewsHdl();
private string [] split_content;
private string split_str= "[pagebr] "; //分页截断字符
private string footPage= " ";
private string id;
private string getPageSize;
private int pagecount; //总页数
private int currentpage; //当前页
protected Const consts=new Const( "SiteConst.xml ");
private void Page_Load(object sender, System.EventArgs e)
{
if(!this.IsPostBack)
{
id=Request.QueryString[ "newsid "];
getPageSize=Request.QueryString[ "page "];
news=newshdl.getNews(id);
this.l_newstitle.Text=news.getNewstitle();
this.l_newsdate.Text=news.getNewsDate();
this.l_newsauthor.Text=news.getNewsAuthor();
this.l_newssource.Text=news.getNewsSource();
split_content=Regex.Split(news.getNewsContent(),split_str,RegexOptions.IgnoreCase);
pagecount=split_content.Length;
getPageSize=this.
/**
*
* 判断新闻内容是否分页
* */
if(split_content.Length> 1)
{
footPage= "第 ";
for(int i=0;i <split_content.Length;i++)
{
currentpage=i+1; //当前页
footPage+= " <a class=pagerTxt href=newsShow.aspx?newsid= "+id+ "&page= "+currentpage+ "> [ "+currentpage+ "] </a> ";
}
if(getPageSize!=null)
footPage+= "页 <font color=red> "+getPageSize+ " </font> / "+pagecount+ " "; //打印当前页和总页数
else
footPage+= "页 <font color=red> 1 </font> / "+pagecount+ " "; //打印当前页和总页数
this.l_page.Text=footPage;
}
else
{
this.l_newscontent.Text=news.getNewsContent();
this.l_page.Visible=false;
}
/**
* 判断提交的页码
* */
if(getPageSize!=null) //判断提交的页码
{
this.l_newscontent.Text=split_content[Convert.ToInt32(getPageSize)-1];
}
else
{
this.l_newscontent.Text=split_content[0];
}
}