老大,问个c#分页算法的问题
1 回答
繁星点点滴滴
TA贡献1803条经验 获得超3个赞
好象没太多意义,那个currint应该就是10除2的结果,整个代码就大概是要显示从currentPage-5到currentPage+5之间这10页,就相当于
1234567891011121314151617 | string output = "" ; int num = 10; if (totalPages < num) num = totalPages-1; //如果总页数不够10 int currint = num / 2; int min = (currentPage >currint ? currentPage - currint : 1); //起始 int max = (currentPage + currint > totalPages ? totalPages : currentPage + currint); //结束 //为避免currentpage小于5时,以及避免最后几页显示不到10项,加上下面两行 if (max <= num) max = num+1; if (max - min < num) min = max - num; if (currentPage > totalPages) currentPage = totalPages; for ( int i=min;i<max;i++) { string css=(i==currentPage? "cpb" : "pageLink" ); output.AppendFormat( "<a class='{4}' href='{0}?pageIndex={1}&pageSize={2}'>{3}</a> " , redirectTo, i, pageSize, i,css); } |
附上修改前后的图(最前的数字为当前页,为简单我直接把当前页用[]标出了)
- 1 回答
- 0 关注
- 473 浏览
添加回答
举报
0/150
提交
取消