日期:2014-05-17 浏览次数:20496 次
public string PageList(int PageSize, int RCount, int currentPage, string UrlHead, string UrlFoot) { int stepNum = 3; int pageRoot = 1; string pageStr = ""; int PCount; if (RCount % PageSize == 0) PCount = RCount / PageSize; else PCount = RCount / PageSize + 1; PCount = PCount == 0 ? 1 : PCount; currentPage = currentPage == 0 ? 1 : currentPage; //pageStr = "<div class=\"pages\"><span>共计: " + RCount.ToString() + " 条记录;分页 " + currentPage.ToString() + " / " + PCount.ToString() + "</span>"; // pageStr = " <li><a href='#'>« Prev</a></li>"; if (currentPage - stepNum < 2) pageRoot = 1; else pageRoot = currentPage - stepNum; int pageFoot = PCount; if (currentPage + stepNum >= PCount) pageFoot = PCount; else pageFoot = currentPage + stepNum; if (pageRoot == 1) { if (currentPage == 1) { pageStr += "<li><a>« 首页</a></li>"; // pageStr += "<a>«</a>"; } else { pageStr += "<li><a href=\"" + UrlHead + "1" + UrlFoot + "\" title=\"首页\">«首页</a></li>"; pageStr += "<li><a href=\"" + UrlHead + (currentPage - 1).ToString() + UrlFoot + "\" title=\"上一页\">«上一页</a></li>"; } } else { pageStr += "<li><a href=\"" + UrlHead + "1" + UrlFoot + "\" title=\"首页\">« 首页</a></li>"; pageStr += "<li><a href=\"" + UrlHead + (currentPage - 1).ToString() + UrlFoot + "\" title=\"上一页\">« 上一页</a></li><li class='disabled'><a>...</a></li>"; } for (int i = pageRoot; i <= pageFoot; i++) { if (i == currentPage) { pageStr += "<li class='active'><a>" + i.ToString() + "</a>"; } else { pageStr += "<li><a href=\"" + UrlHead + i.ToString() + UrlFoot + "\" title=\"第 " + i.ToString() + " 页\">" + i.ToString() + "</a></li>"; } if (i == PCount) break; } if (pageFoot == PCount) { if (PCount == currentPage) { //pageStr += "<li><a>下一页»</a></li>"; pageStr += "<li><a>尾页»</a></li>"; } else { pageStr += "<li><a href=\"" + UrlHead + (currentPage + 1).ToString() + UrlFoot + "\" title=\"下一页\">下一页 »</a></li>"; pageStr += "<li><a href=\"" + UrlHead + PCount.ToString() + UrlFoot + "\" title=\"尾页\">尾页 »</a></li>";