日期:2014-05-18 浏览次数:20417 次
/// <summary> /// 分页方法 /// </summary> /// <param name="currentUrl">页面地址</param> /// <param name="pageName">分页的参数名</param> /// <param name="recordCount">总条数</param> /// <param name="pageSize">页面每页显示的条数</param> /// <param name="pageCount">页面底部显示多少个分页按钮 如:[第1页] [第2页] [第3页] [第4页] [第5页] 那么就是5</param> /// <param name="pageIndex">当前页</param> /// <returns></returns> public string GetPageBusiness(string currentUrl, string pageName, string condition, int recordCount, int pageSize, int pageCount, int pageIndex) { if (recordCount <= pageSize) { return ""; }; int totalPageCount = (recordCount / pageSize) + ((recordCount % pageSize) > 0 ? 1 : 0); //页码超过最大页时转到最后一页 if (totalPageCount < pageIndex) { Response.Redirect(currentUrl + "?" + pageName + "=" + totalPageCount); } StringBuilder address = new StringBuilder(); int startIndex = (pageIndex - pageCount <= 0) ? 1 : pageIndex - pageCount; int endIndex = (pageIndex + pageCount > totalPageCount) ? totalPageCount : (pageIndex + pageCount); condition = String.IsNullOrEmpty(condition) ? "" : ("&" + condition); if (pageIndex > 1) { address.Append("<a href='" + currentUrl + "?" + condition + "'>首页</a> "); address.Append("<a href='" + currentUrl + "?" + pageName + "=" + (pageIndex - 1) + condition + "'>上一页</a> "); } for (int i = startIndex; i <=endIndex; i++) { if (i == pageIndex) { address.Append("<b>" + i.ToString() + "</b> "); } else { address.Append("<a href='" + currentUrl + "?" + pageName + "=" + i.ToString() + condition + "' title='第"+i.ToString()+"页'>[" + i.ToString() + "]</a>"); } } if (pageIndex < totalPageCount) { address.Append("<a href='" + currentUrl + "?" + pageName + "=" + (pageIndex + 1) + condition + "'>下一页</a> "); } address.Append("<a href='" + currentUrl + "?" + pageName + "=" + totalPageCount + condition + "'>尾页</a>"); return address.ToString(); }
public static string CreatePager(int pageIndex, int pageCount, int totalRecord) { StringBuilder append = new StringBuilder(); append.Append("<div class=\"SelectPager\">"); int step = 5, StartPage = 1, EndPage = pageIndex + step; if (pageIndex > step) { StartPage = pageIndex - step; } if (EndPage &