using System; using System.Collections.Generic; using System.Web; using System.Text; using System.Text.RegularExpressions; namespace cofcms { public class PagingCollection<T> { private int pagezise; public int Pagezise { get { return pagezise; } set { pagezise = value; } } private int pageindex; public int Pageindex { get { return pageindex; } set { pageindex = value; } } private int TotalCount; public int TotalCount1 { get { return TotalCount; } set { TotalCount = value; } } private int TotalPage=0; public int TotalPage1 { get { return TotalPage; } set { TotalPage = value; } } private string url; public string Url { get { return url; } set { url = value; } } private string urlparms; public string Urlparms { get { return urlparms; } set { urlparms = value; } } /// <summary> /// 分页数据构造 /// </summary> /// <param name="source"></param> /// <param name="pageindex"></param> /// <param name="pagezise"></param> /// <param name="totalcount"></param> /// <param name="url"></param> public PagingCollection(int pageindex, int pagezise, int totalcount, string url) { this.pageindex = pageindex; this.pagezise = pagezise; TotalCount = totalcount; TotalPage = (int)Math.Ceiling(TotalCount / (double)pagezise); this.url = url; } public PagingCollection(int pageindex, int pagezise, int totalcount, string url,string urlparms) { this.pageindex = pageindex; this.pagezise = pagezise; TotalCount = totalcount; TotalPage = (int)Math.Ceiling(TotalCount / (double)pagezise); this.url = url; this.urlparms = urlparms; } #region 分页属性 返回分页数据 public string GetPatePar { get { if (TotalCount1 > 0) { StringBuilder str = new StringBuilder(); int startpage = (pageindex - 1) / 10 * 10 + 1; int endpage = (pageindex - 1) / 10 * 10 + 10; int x = endpage > TotalPage ? TotalPage : endpage; str.Append("<div style=" color:#1E5494;" mce_style=" color:#1E5494;">共" + TotalPage1 + "页 / 当前第" + pageindex + "页"); if (HasPreviousPage) { str.Append("<a href=" + url + " mce_href=" + url + "?page=1" + GetURLParms + "" + urlparms + ">首页</a>"); str.Append("<a href=" + url + " mce_href=" + url + "?page=" + (pageindex - 1) + GetURLParms + "" + urlparms + ">上一页</a>"); } else { str.Append("<a href="#" mce_href="#">首页</a>"); str.Append("<a href="#" mce_href="#">上一页</a>"); } for (int i = startpage; i <= x; i++) { if (i == pageindex) { str.Append(string.Format("<a style="margin-left:3px; margin-right:3px;padding:2px 4px 2px 4px;color:red;border:1px solid #cccccc;background-color:#ffffff; " mce_style="margin-left:3px; margin-right:3px;padding:2px 4px 2px 4px;color:red;border:1px solid #cccccc;background-color:#ffffff; ">" + i + "</a>")); } else { str.Append(string.Format("<a style="margin-left:3px; margin-right:3px;" mce_style="margin-left:3px; margin-right:3px;" href=" + url + " mce_href=" + url + "?page=" + i + GetURLParms + "" + urlparms + ">" + i + "</a>")); } } if (HasNextPage) { str.Append("<a href=" + url + " mce_href=" + url + "?page=" + (pageindex + 1) + GetURLParms + "" + urlparms + ">下一页</a>"); str.Append("<a href=" + url + " mce_href=" + url + "?page=" + TotalPage + GetURLParms + "" + urlparms + ">尾页</a>"); } else { str.Append("<a href="#" mce_href="#">下一页</a>"); str.Append("<a href="#" mce_href="#">尾页</a>"); } str.Append("</div>"); return str.ToString(); } else { return "<font color=red>暂无数据!</font>"; } } } #endregion /// <summary> /// url重写 /// </summary> private string GetURLParms { get { string query = HttpContext.Current.Request.Url.Query; query = Regex.Replace(query, @"\?page=\d*", "", RegexOptions.Compiled); return query; } } /// <summary> ///判断是否有上一页 /// </summary> public bool HasPreviousPage { get { return (pageindex > 1); } } /// <summary> ///判断是否有下一页 /// </summary> public bool HasNextPage { get { return (pageindex < TotalPage); } } } /// <summary> /// 分页数据类 /// </summary> /// <typeparam name="T"></typeparam> public class PageBean<T> { IList<T> datasource = new List<T>(); public IList<T> Datasource { get { return datasource; } set { datasource = value; } } int pagesum; public int Pagesum { get { return pagesum; } set { pagesum = value; } } public PageBean(IList<T> datasource, int pagesum) { this.datasource = datasource; this.pagesum = pagesum; } public PageBean() { // // TODO: 在此处添加构造函数逻辑 // } } }
asp.net 自定义分页方法
最新推荐文章于 2019-10-04 16:07:02 发布