首页 > 代码库 > 自己重构的一个分页
自己重构的一个分页
/// <summary> /// 分页控件(wu) /// </summary> /// <param name="RecordCount">记录数</param> /// <param name="curPage">当前页</param> /// <param name="PageSize">一页多少条数据</param> /// <param name="actionURL">分页跳转链接</param> /// <param name="argName">URL当前页参数命名</param> /// <returns></returns> public static string ToPageHtml(int RecordCount, int curPage, int PageSize, string actionURL, string argName) { StringBuilder sb = new StringBuilder(); if (RecordCount > 0) { int pageSum = RecordCount / PageSize; //总页数 if (RecordCount % PageSize > 0) { //求余 pageSum = pageSum + 1; } int pageMaxSum = 3; //分页栏当前页按钮或左或右最多显示的按钮 if (curPage < 1) curPage = 1; if (curPage > pageSum) curPage = pageSum; sb.AppendLine("<div class=\"liem-bottom\"><ul class=\"tunepage\" >\r\n"); //上一页 if (1 == curPage) { //sb.AppendLine("<li><a>上一页</a></li>"); } else { sb.AppendFormat("<li><a href=http://www.mamicode.com/"" + GetAnchorUrl(curPage - 1, actionURL, argName) + "\">上一页</a></li>"); } var startIndex = 1; var endIndex = pageSum; if (pageSum > pageMaxSum * 2 + 1) { if (curPage - pageMaxSum > 0) { if (curPage + pageMaxSum < pageSum) { startIndex = curPage - pageMaxSum; endIndex = curPage + pageMaxSum; } else { startIndex = pageSum - pageMaxSum * 2; } } else { endIndex = pageMaxSum * 2 + 1; } } if (pageSum > 1) { if (startIndex.Equals(2)) { sb.AppendLine("<li><a href=http://www.mamicode.com/"" + GetAnchorUrl(1, actionURL, argName) + "\">1</a></li>"); endIndex--; } else if (startIndex > 2) { sb.AppendLine("<li><a href=http://www.mamicode.com/"" + GetAnchorUrl(1, actionURL, argName) + "\">1</a></li>"); sb.AppendLine("<li>...</li>"); } //页码 for (var i = startIndex; i <= endIndex; i++) { if (curPage == i) { sb.AppendLine("<li><a class=\"current\">" + curPage + "</a></li>"); } else { sb.AppendLine("<li><a href=http://www.mamicode.com/"" + GetAnchorUrl(i, actionURL, argName) + "\">" + i + "</a></li>"); } } if (endIndex < pageSum - 1) { sb.AppendLine("<li>…</li>"); sb.AppendLine("<li><a href=http://www.mamicode.com/"" + GetAnchorUrl(pageSum, actionURL, argName) + "\">" + pageSum + "</a></li>"); } else if (endIndex < pageSum) { sb.AppendLine("<li><a href=http://www.mamicode.com/"" + GetAnchorUrl(pageSum, actionURL, argName) + "\">" + pageSum + "</a></li>"); } } //下一页 if (curPage == pageSum || pageSum == 0) { //sb.AppendLine("<li><a>下一页</a></li>"); } else { sb.AppendLine("<li><a href=http://www.mamicode.com/"" + GetAnchorUrl(curPage + 1, actionURL, argName) + "\">下一页</a></li>"); } sb.AppendLine("\r\n</ul></div>"); } return sb.ToString(); } private static string GetAnchorUrl(int curPage, string actionURL, string argName) { if (actionURL.IndexOf("?") > 0) { return string.Format("{0}&{1}={2}", actionURL, argName, curPage); } return string.Format("{0}?{1}={2}", actionURL, argName, curPage); }
create procedure usp_FenYe@pageIndex int,@pageCount int=10,@pageTotalCount int outputasbegin --计算出总页数 declare @totalData int; set @totalData=http://www.mamicode.com/(select count(*) from T) set @pageTotalCount=Ceiling(@totalData*1.0/@pageCount); --得到数据 select * from (select *,num=row_number() over(order by id) from T) as t where t.num between @pageCount * (@pageInde-1)+1 and @pageCount* @pageIndex;endgo
写上一个存储过程分页,不解释,有点基础的人应该看得懂。
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。