关于一个分页函数的使用问题
我找了个分页函数,这是第一次用下的分页函数,如下
public static int GetPageNum(int recordcount, int pagesize) { int num = 0; if (pagesize == 0) return 0; if (recordcount % pagesize == 0) num = recordcount / pagesize; else num = Convert.ToInt32(Math.Round(Convert.ToDouble(recordcount / pagesize) , 0 )) + 1; return num; } /// <summary> /// 获取显示分页的字符串 /// </summary> /// <param name="curPage">当前页</param> /// <param name="pages">总页数</param> /// <param name="link">链接地址</param> /// <param name="maxNum">每次显示的最多分页数字数</param> /// <returns></returns> public static string GetPagingString(int curPage ,int recordcount , int pageSize, int pages, string link , int maxNum) { if (pages == 0) return ""; string strPre = "" , strNext = "" , strNums = ""; //确保当前页在最大页面以内 if (curPage < 1) curPage = 1; else if (curPage > pages) curPage = pages; if (pages == 1) { return ""; } else if (curPage > 1 && curPage < pages ){ strPre = "<a href=\"" + string.Format(link, curPage - 1) + "\">上一页</a>"; strNext = "<a href=\"" + string.Format(link, curPage + 1) + "\">下一页</a>"; } else if (curPage <= 1) { strPre = "上一页"; strNext = "<a href=\"" + string.Format(link, curPage + 1) + "\">下一页</a>"; } else if( curPage >= pages ) { strPre = "<a href=\"" + string.Format(link, curPage - 1) + "\">上一页</a>"; strNext = "下一页"; } int startNum = 0 ,endNum = 0; if (pages <= maxNum) { //如果总页数不大于每次最大显示的分页数 startNum = 1; endNum = pages; } else if (curPage < maxNum) { //总页数大于 startNum = 1; endNum = maxNum; } else if (curPage >= maxNum && curPage <= pages) { if (curPage % maxNum == 0) //为每次最大分页数的整数倍时 startNum += curPage - maxNum + 1; else startNum = curPage - (curPage % maxNum) + 1; endNum = startNum + maxNum - 1; if (endNum > pages) //如果结束数字比总页数还大,则取总页数 endNum = pages; } for (int i = startNum; i <= endNum; i++) { if (i == curPage) strNums += " <b>第" + i + "页</b> "; else strNums += "<a href=\"" + string.Format(link, i) + "\">" + i + "</a> "; } if( startNum > 1 ) strNums += " ... "; return "<div id=\"pagelist\">共" + recordcount + "条 每页" + pageSize + "条 " + curPage + "/" + pages + " " + strPre + " " + strNums + " " + strNext + "</div>"; }