asp.net C#怎么写翻页类?

 我来答
爵爷2货2017
2014-06-26 · TA获得超过641个赞
知道答主
回答量:167
采纳率:0%
帮助的人:63万
展开全部
这是我以前写的分页类,一直在用着,拷出来给你,哪里不明白就问。 ======================================================= using System; using System.Data; using System.Text; using System.Collections.Generic; /// <summary> /// 带分页信息的数据 /// </summary> public class PaginationData { /// <summary> /// 缺省每页显示记录数 /// </summary> public static int PAGE_SIZE = 18; /// <summary> /// 缺省分页显示页码个数 /// </summary> private static int NUM_SCALAR = 10; /// <summary> /// 每页显示记录数 /// </summary> private int _PageSize; /// <summary> /// 记录总数 /// </summary> private int _RecordCount; /// <summary> /// 总页数 /// </summary> private int _PageCount; /// <summary> /// 当前页码 /// </summary> private int _PageIndex; /// <summary> /// 分页显示页码个数 /// </summary> private int _NumScalar; /// <summary> /// 分页链接字符 /// </summary> private string _PageLinkString; /// <summary> /// 列表数据 /// </summary> private DataTable _DataList; public PaginationData() { } public DataTable DataList { get; set; } public int RecordCount { set { this._RecordCount = value; } get { return this._RecordCount; } } public int PageCount { get { //自动计算总页数 if (this.RecordCount > 0) { this._PageCount = this.RecordCount / this.PageSize; if (this.RecordCount % this.PageSize > 0) { this._PageCount++; } } return this._PageCount; } } /// <summary> /// 当前页码 /// </summary> public int PageIndex { set { this._PageIndex = value; } get { return _PageIndex; } } /// <summary> /// 每页记录数 /// </summary> public int PageSize { set { this._PageSize = value; } get { if (this._PageSize <= 0) { this._PageSize = PAGE_SIZE; } return this._PageSize; } } /// <summary> /// 分页显示页码个数 /// </summary> public int NumScalar { set { this.NumScalar = value; } get { if (this._NumScalar <= 0) { this._NumScalar = NUM_SCALAR; } return this._NumScalar; } } /// <summary> /// 分页链接字符 /// </summary> public string PageLinkString { get { this._PageLinkString = CreatePageLinkString(); return _PageLinkString; } } /// <summary> /// 创建分页链接字符 /// </summary> /// <returns></returns> private string CreatePageLinkString() { System.Text.StringBuilder sb = new System.Text.StringBuilder(); if (this.RecordCount == 0) { sb.Append("<div id=\"plink\">共有0条记录</div>"); } else { int pageNum = 0; int leftCount, rightCount; if (this.NumScalar % 2 == 0) { leftCount = this.NumScalar / 2; rightCount = this.NumScalar / 2 - 1; } else { leftCount = rightCount = this.NumScalar / 2; } sb.Append("<div id=\"plink\">") .Append("共有<span id=\"recordcount\">").Append(this.RecordCount).Append("</span>条记录") .Append("<span id=\"curpage\">").Append(this.PageIndex).Append("</span>/<span id=\"pagecount\">").Append(this.PageCount).Append("</span>"); if (this.PageIndex == 1) { sb.Append("<span id=\"previous_off\" title=\"已经处在第1页\">7</span>"); //上一页符号(不可用) } else { sb.Append("<a id=\"previous\" href=\"javascript:pageIndex(").Append(this.PageIndex - 1).Append(");\" title=\"上一页\">7</a>"); } if ((this.PageIndex - leftCount) > 1) { sb.Append("<a id=\"link\" href=\"javascript:pageIndex(").Append(1).Append(");\">").Append(1).Append("</a>") .Append("<span id=\"hide\">..</span>"); } if ((this.PageIndex - leftCount) <= 1) { for (pageNum = 1; pageNum < this.PageIndex; pageNum++) { sb.Append("<a id=\"link\" href=\"javascript:pageIndex(").Append(pageNum).Append(");\">").Append(pageNum).Append("</a>"); } } else { for (pageNum = this.PageIndex - leftCount; pageNum < this.PageIndex; pageNum++) { sb.Append("<a id=\"link\" href=\"javascript:pageIndex(").Append(pageNum).Append(");\">").Append(pageNum).Append("</a>"); } } sb.Append("<span id=\"current\">").Append(this.PageIndex).Append("</span>"); int identity = 1; for (pageNum = this.PageIndex + 1; pageNum <= this.PageCount && identity <= rightCount; pageNum++) { sb.Append("<a id=\"link\" href=\"javascript:pageIndex(").Append(pageNum).Append(");\">").Append(pageNum).Append("</a>"); identity++; } if ((this.PageIndex + rightCount) < this.PageCount) { sb.Append("<span id=\"hide\">..</span>") .Append("<a id=\"link\" href=\"javascript:pageIndex(").Append(this.PageCount).Append(");\">").Append(this.PageCount).Append("</a>"); } if (this.PageIndex == this.PageCount) { sb.Append("<span id=\"next_off\" title=\"已经处在最后1页\">8</span>"); //下一页符号(不可用) } else { sb.Append("<a id=\"next\" href=\"javascript:pageIndex(").Append(this.PageIndex + 1).Append(");\" title=\"下一页\">8</a>"); } sb.Append("</div>"); } return sb.ToString(); } }

希望采纳
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式