/// <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=\"" + 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=\"" + GetAnchorUrl(1, actionURL, argName) + "\">1</a></li>"); endIndex--; } else if (startIndex > 2) { sb.AppendLine("<li><a href=\"" + 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=\"" + GetAnchorUrl(i, actionURL, argName) + "\">" + i + "</a></li>"); } } if (endIndex < pageSum - 1) { sb.AppendLine("<li>…</li>"); sb.AppendLine("<li><a href=\"" + GetAnchorUrl(pageSum, actionURL, argName) + "\">" + pageSum + "</a></li>"); } else if (endIndex < pageSum) { sb.AppendLine("<li><a href=\"" + GetAnchorUrl(pageSum, actionURL, argName) + "\">" + pageSum + "</a></li>"); } } //下一页 if (curPage == pageSum || pageSum == 0) { //sb.AppendLine("<li><a>下一页</a></li>"); } else { sb.AppendLine("<li><a href=\"" + 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); }View Code
create procedure usp_FenYe @pageIndex int, @pageCount int=10, @pageTotalCount int output as begin --计算出总页数 declare @totalData int; set @totalData=(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; end goView Code
写上一个存储过程分页,不解释,有点基础的人应该看得懂。