一个防google分页的实例
/// param name="total"总记录数/param /// param name="per"每页记录数/param /// param name="page"当前页数/param /// param name="query_string"Url参数/param /// 返回一个带HTML代码的分页样式(字符串) private string Pagination(int total, int pe
/// 总记录数
/// 每页记录数
/// 当前页数
/// Url参数
/// 返回一个带HTML代码的分页样式(字符串)
private string Pagination(int total, int per, int page, string query_string)
{
int allpage = 0;
int next = 0;
int pre = 0;
int startcount = 0;
int endcount = 0;
string pagestr = "";
if (page //计算总页数
if (per != 0)
{
allpage = (total / per);
allpage = ((total % per) != 0 ? allpage + 1 : allpage);
allpage = (allpage == 0 ? 1 : allpage);
}
next = page + 1;
pre = page - 1;
startcount = (page + 5) > allpage ? allpage - 9 : page - 4;//中间页起始序号
//中间页终止序号
endcount = page if (startcount if (allpage pagestr = "共" + allpage + "页/第" + page + "页 ";
//中间页处理,这个增加时间复杂度,减小空间复杂度
for (int i = startcount; i {
pagestr += page == i ? " " + i + "" : " " + i + "";
}
return pagestr;
}