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 name="PageInfo">Literal控件 </param> public void CutPageMethod(Literal pt) { StringBuilder orderInfoSb = new StringBuilder(); orderInfoSb.Append("<span style=/"width:1000px/"><tr id=/"pagination-digg/"><th style=/"width:180px/">"); orderInfoSb.Append("当前" + CurretPage + "/" + PageCount + "页 共" + Count + "条数据"); orderInfoSb.Append("</th><th class=/"previous-off/" style=/"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>");
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 CutPageTest : System.Web.UI.Page { CutPage cp=new CutPage(); string id; protected void Page_Load(object sender, EventArgs e) { ShowPageData(DbHelperSQL.QueryReDt("select * from test",GlobalConfig.TCCLineDbHelper), "CutPageTest.aspx"); //Response.Write();
} public void ShowPageData(DataTable dt,string url) { //cp.CssUrl = "Style/PageCut.css"; id = Request.QueryString["id"]; cp.ID = id; cp.DT = dt; had.InnerHtml = "<link href=/"css/text/" src='" + cp.CssUrl + "'/>"; if (id == null || id == "") { cp.CurretPage = 1; } else { cp.CurretPage = Convert.ToInt32(id); } cp.Url = url; cp.DataCount = 2; cp.Count = cp.DT.Rows.Count; cp.CutPageMethod(lt); for (int i = cp.StartID; i < cp.EndID; i++) { LiInfo.Text += cp.DT.Rows[i][1].ToString() + "<br/>"; } } }