分页页码显示的算法
分页后,想实现只显示固定个数的页码,比如显示5个,12345,当点击4的时候,显示23456
我的循环是这么写的
很明显,是不对的
有没有人可以帮我修改一下
for (int i = (pds.CurrentPageIndex - 3) > 0 ? (pds.CurrentPageIndex - 3) : 1; i <= ((pds.CurrentPageIndex + 5) < pds.PageCount ? (pds.CurrentPageIndex + 5) : pds.PageCount); i++)
}
else
{
pags[i] = i + 1;
}
}
}
[解决办法]
int pageIndex= int.Parse(Request["pageIndex"]);
int ps=(pageIndex/5) + (pageIndex%5==0?0:1);
int pageCount=(rowCount/pageSize) + (rowCount%pageSize==0?0:1);
for(int i=5 * (ps-1) + 1;i<=ps * 5 && i<=pageCount;i++)
{
.....
}