复制代码 代码如下:
using System;
using System.Data;
using System.Configuration;
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;
using System.Text;
/// <summary>
///CutPage 的摘要说明
/// </summary>
public class CutPage
{
public CutPage()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
#region 私有成员变量
private string url; //分页时所用到的页面地址
private int count; //数据总条数
private int pageCount; //总页数
private int curretPage; //当前页数
private string id; //接收传递参数的值
private int startId; //数据循环的开始值
private int endId; //数据结束的值
private DataTable dt; //数据dt值
private int dataCount; //每页现实的数据条数
private string cssUrl; //cssURL地址
#endregion
#region 公共变量
/// <summary>
/// Url地址
/// </summary>
public string Url
{
get
{
return url;
}
set
{
this.url = value;
}
}
/// <summary>
/// 数据总条数
/// </summary>
public int Count
{
get
{
return count;
}
set
{
this.count = value;
}
}
/// <summary>
/// 数据总页数(该字段只读)
/// </summary>
public int PageCount
{
get
{
if (count % dataCount == 0)
{
return Convert.ToInt32(count / dataCount);
}
else
{
return Convert.ToInt32(count / dataCount) + 1;
}
}
}
/// <summary>
/// 分页样式表url
/// </summary>
public string CssUrl
{
get { return cssUrl; }
set { this.cssUrl = value; }
}
/// <summary>
/// 当前页数
/// </summary>
public int CurretPage
{
get { return this.curretPage; }
set { this.curretPage = value; }
}
/// <summary>
/// 传递的参数值
/// </summary>
public string ID
{
get { return this.id; }
set { this.id = value; }
}
/// <summary>
/// 数据开始值(该字段只读)
/// </summary>
public int StartID
{
get
{
if (curretPage == 1)
{
return 0;
}
else
{
return (curretPage-1) * dataCount;
}
}
}
/// <summary>
/// 数据结束的值(该字段只读)
/// </summary>
public int EndID
{
get
{
if (CurretPage == PageCount)
{
return this.DT.Rows.Count;
}
else
{
return (curretPage) * dataCount;
}
}
}
/// <summary>
/// 用于分页的数据源
/// </summary>
public DataTable DT
{
get { return this.dt; }
set { this.dt = value; }
}
/// <summary>
/// 每页显示的数据条数
/// </summary>
public int DataCount
{
get { return this.dataCount; }
set { this.dataCount = value; }
}
#endregion
/// <summary>
/// 分页方法(生成分页代码的过程)
/// </summary>
/// <param>Literal控件 </param>
public void CutPageMethod(Literal pt)
{
StringBuilder orderInfoSb = new StringBuilder();
orderInfoSb.Append("<span style=https://www.jb51.net/article/\"width:1000px\"><tr id=https://www.jb51.net/article/\"pagination-digg\"><th style=https://www.jb51.net/article/\"width:180px\">");
orderInfoSb.Append("当前" + CurretPage + "https://www.jb51.net/" + PageCount + "页 共" + Count + "条数据");
orderInfoSb.Append("</th><th class=https://www.jb51.net/article/\"previous-off\" style=https://www.jb51.net/article/\"align:right\">");
if (Convert.ToInt32(this.ID) == 1)
{
orderInfoSb.Append("<a href='#' disabled='flase'>首页</a>");
}
else
{
orderInfoSb.Append("<a href='" + Url + "?id=1'>首页</a>");
}
orderInfoSb.Append("</th><th>");
if (Convert.ToInt32(this.ID )== 1 || this.ID==null || this.ID==string.Empty)
{
orderInfoSb.Append("<a href='#'disabled='flase'>上一页</a>");
}
else
{
orderInfoSb.Append("<a href='" + Url + "?id="+Convert.ToString(CurretPage-1)+"'>上一页</a>");
}
if (Convert.ToInt32(this.ID) < PageCount)
{
orderInfoSb.Append("<a href='" + Url + "?id=" +Convert.ToString(CurretPage + 1) + "'>下一页</a>");
}
else
{
orderInfoSb.Append("<a href='#'disabled='flase'>下一页</a>");
}
orderInfoSb.Append("</th><th>");
if (Convert.ToInt32(this.ID) == PageCount)
{
orderInfoSb.Append("<a href='#' disabled='flase'>末页</a>");
}
else
{
orderInfoSb.Append("<a href='" + Url + "?id="+Convert.ToString(PageCount)+"'>末页</a>");
}
orderInfoSb.Append("</th></tr></span>");
pt.Text = orderInfoSb.ToString();
}
}
样式大家可以自己添,老实说没什么技术含量。
前台代码:
代码
复制代码 代码如下: