设置分页页码
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了设置分页页码相关的知识,希望对你有一定的参考价值。
/// <summary> /// 设置分页页码 /// </summary> /// <param name="pageNum">当前页码</param> /// <param name="pageCount">总页数</param> /// <param name="sideNum">每页显示条数</param> /// <param name="startNum">开始页码</param> /// <param name="endNum">结束页码</param> public static void calcPage(int pageNum, int pageCount, int sideNum, ref int startNum, ref int endNum) { if (pageCount <= sideNum) { endNum = pageCount; } else { if ((sideNum + pageNum) >= pageCount) { endNum = pageCount; } else { endNum = sideNum + pageNum; if ((sideNum + pageNum) <= (2 * sideNum + 1)) { if ((2 * sideNum + 1) >= pageCount) { endNum = pageCount; } else { endNum = 2 * sideNum + 1; } } else { endNum = sideNum + pageNum; } } } if (pageNum <= sideNum) { startNum = 1; } else { if ((pageNum + sideNum) >= pageCount) { if ((2 * sideNum + 1) >= pageCount) { if ((pageCount - 2 * sideNum) >= 1) { startNum = pageCount - 2 * sideNum; } else { startNum = 1; } } else { startNum = pageCount - 2 * sideNum; } } else { if ((pageNum - sideNum) >= 1) { startNum = pageNum - sideNum; } else { startNum = 1; } } } }
以上是关于设置分页页码的主要内容,如果未能解决你的问题,请参考以下文章