如何实现asp.net长篇文章分页
2013-11-27
展开全部
实现思路是:后台管理员文章发布的时候自己手动添加分页符,后台我用的也是FCKeditor,所以修改了他的source增加了自己的button。在button的事件里写上自己的代码,当然就是直接insert innerhtml自己的分页标志了,我目前用的是|,|,|,|,|,|当然可以自定义其他的。首先提供个类库。
1 ContentPager .cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.ComponentModel;
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.Web.SessionState;
/// <summary>
/// ContentPager 的摘要说明
/// </summary>
public class ContentPager : System.Web.UI.Page
{
private System.Web.UI.WebControls.HyperLink lnknext;
private System.Web.UI.WebControls.HyperLink lnkprev;
private System.Web.UI.WebControls.HyperLink lnkfist;
private System.Web.UI.WebControls.HyperLink lnklast;
private System.Web.UI.WebControls.Label pagenum;
private System.Web.UI.WebControls.Label pagecount;
private System.Web.UI.WebControls.Label displaycontent;
public ContentPager()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public void datapager(string content,string query)
{
string PagerSplit = System.Configuration.ConfigurationManager.AppSettings["PagerSplit"];//从web.config中获取分页符,当然这里可以自己定义,为了方便还是放到配置文件或者数据库中。
string[] contentArray = StringSplit(content, PagerSplit);//这里是一个方法,摘自网上
int PageCount = contentArray.Length;
this.pagecount.Text = "共<b><font color='#FF0000'>" + PageCount.ToString() + "</font></b>页";
int CurPage;//确定当前页数
if (System.Web.HttpContext.Current.Request.Params["Page"] != null)
{
CurPage = Convert.ToInt32(System.Web.HttpContext.Current.Request.Params["Page"]);
}
else
{
CurPage = 1;
}
if (CurPage < 1) CurPage = 1;
if (Convert.ToInt32(System.Web.HttpContext.Current.Request.Params["Page"]) > PageCount)
{
CurPage = PageCount;
}
1 ContentPager .cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.ComponentModel;
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.Web.SessionState;
/// <summary>
/// ContentPager 的摘要说明
/// </summary>
public class ContentPager : System.Web.UI.Page
{
private System.Web.UI.WebControls.HyperLink lnknext;
private System.Web.UI.WebControls.HyperLink lnkprev;
private System.Web.UI.WebControls.HyperLink lnkfist;
private System.Web.UI.WebControls.HyperLink lnklast;
private System.Web.UI.WebControls.Label pagenum;
private System.Web.UI.WebControls.Label pagecount;
private System.Web.UI.WebControls.Label displaycontent;
public ContentPager()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public void datapager(string content,string query)
{
string PagerSplit = System.Configuration.ConfigurationManager.AppSettings["PagerSplit"];//从web.config中获取分页符,当然这里可以自己定义,为了方便还是放到配置文件或者数据库中。
string[] contentArray = StringSplit(content, PagerSplit);//这里是一个方法,摘自网上
int PageCount = contentArray.Length;
this.pagecount.Text = "共<b><font color='#FF0000'>" + PageCount.ToString() + "</font></b>页";
int CurPage;//确定当前页数
if (System.Web.HttpContext.Current.Request.Params["Page"] != null)
{
CurPage = Convert.ToInt32(System.Web.HttpContext.Current.Request.Params["Page"]);
}
else
{
CurPage = 1;
}
if (CurPage < 1) CurPage = 1;
if (Convert.ToInt32(System.Web.HttpContext.Current.Request.Params["Page"]) > PageCount)
{
CurPage = PageCount;
}
2013-11-27
展开全部
/// <summary>
/// 分页
/// </summary>
/// <param name="iPageSize">每页显示条数</param>
/// <param name="iCurrentPage">当前页</param>
/// <param name="iRecordNumber">总记录数</param>
/// <returns></returns>
// <param name="iParameters">参数, String iParameters</param>
public StringBuilder Pagination(int iPageSize, Int32 iCurrentPage)
{
Int32 iRecordNumber = GetRecordNumber(0, 0);
//总页数
Int32 PageNnmber = iRecordNumber / iPageSize;
//Previous 上一页
Int32 PrevPage = iCurrentPage - 1;
Int32 NextPage = iCurrentPage + 1;
if (iCurrentPage == 1)
PrevPage = 1;
if (iCurrentPage == PageNnmber)
NextPage = PageNnmber;
StringBuilder sb = new StringBuilder();
sb.Append("总记录:" + iRecordNumber + "当前:" + iCurrentPage + "/" + PageNnmber + "<a href=showArticles.aspx?Page=" + PrevPage + ">上一页</a>|<a href=showArticles.aspx?Page=" + NextPage + ">下一页</a>");
return sb;
}
、、、
Int32 StartIndex= (iCurrentPage - 1)*iPageSize + 1;
Int32 EndIndex = (iCurrentPage - 1) *iPageSize+ 1 +iPageSize - 1;
数据库 sql语句 select * from (SELECT *,row_number() OVER (ORDER BY id DESC)AS RowNum
from abc) [表] where RowNum between StartIndex and EndIndex
此时获得的是已经分好的表,表里有规定条数数据 例如每页5条
代码页里 pageload接收Pagination方法传递的Page值
if (!Page.IsPostBack)
{
if(!String.IsNullOrEmpty(Request.QueryString.Get("Page")))
{
//当前页
int currentPage = Convert.ToInt32(Request.QueryString.Get("Page"));
}
}
在把currentPage 传给Pagination方法,当然不要忘了在循环输出你获得的表
}
一个简单的小例子 可以帮你理清思路,太麻烦了也不好 哈哈哈
/// 分页
/// </summary>
/// <param name="iPageSize">每页显示条数</param>
/// <param name="iCurrentPage">当前页</param>
/// <param name="iRecordNumber">总记录数</param>
/// <returns></returns>
// <param name="iParameters">参数, String iParameters</param>
public StringBuilder Pagination(int iPageSize, Int32 iCurrentPage)
{
Int32 iRecordNumber = GetRecordNumber(0, 0);
//总页数
Int32 PageNnmber = iRecordNumber / iPageSize;
//Previous 上一页
Int32 PrevPage = iCurrentPage - 1;
Int32 NextPage = iCurrentPage + 1;
if (iCurrentPage == 1)
PrevPage = 1;
if (iCurrentPage == PageNnmber)
NextPage = PageNnmber;
StringBuilder sb = new StringBuilder();
sb.Append("总记录:" + iRecordNumber + "当前:" + iCurrentPage + "/" + PageNnmber + "<a href=showArticles.aspx?Page=" + PrevPage + ">上一页</a>|<a href=showArticles.aspx?Page=" + NextPage + ">下一页</a>");
return sb;
}
、、、
Int32 StartIndex= (iCurrentPage - 1)*iPageSize + 1;
Int32 EndIndex = (iCurrentPage - 1) *iPageSize+ 1 +iPageSize - 1;
数据库 sql语句 select * from (SELECT *,row_number() OVER (ORDER BY id DESC)AS RowNum
from abc) [表] where RowNum between StartIndex and EndIndex
此时获得的是已经分好的表,表里有规定条数数据 例如每页5条
代码页里 pageload接收Pagination方法传递的Page值
if (!Page.IsPostBack)
{
if(!String.IsNullOrEmpty(Request.QueryString.Get("Page")))
{
//当前页
int currentPage = Convert.ToInt32(Request.QueryString.Get("Page"));
}
}
在把currentPage 传给Pagination方法,当然不要忘了在循环输出你获得的表
}
一个简单的小例子 可以帮你理清思路,太麻烦了也不好 哈哈哈
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
建议你使用pageoffice。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询