asp.net 分页链接方法
程序员文章站
2024-03-07 21:15:33
复制代码 代码如下:/// /// 分页链接 /// ///
/// <summary>
/// 分页链接
/// </summary>
/// <param name="pagesize"></param>
/// <param name="recordcount"></param>
/// <param name="currentpage"></param>
/// <param name="prev">当前页前面显示的数量</param>
/// <param name="next">当前页后面显示的数量</param>
/// <returns></returns>
public string pagelink(int pagesize, int recordcount, int currentpage, int prev, int next)
{
int pagecount = recordcount % pagesize == 0 ? (recordcount / pagesize) : ((int)math.ceiling((double)recordcount / pagesize));
stringbuilder sb = new stringbuilder();
if (currentpage > 1 && recordcount > 1)
{
sb.append("<a href=\"?page=");
sb.append((currentpage - 1).tostring());
sb.append("\">前一页</a> ");
}
if (currentpage > prev + 1)
sb.append("<a href=\"?page=1\">1</a> ... ");
if (currentpage < prev)
next = next + prev - currentpage + 1;
if (next > pagecount - currentpage)
prev = prev + next - (pagecount - currentpage);
for (int i = 1; i <= pagecount; i++)
{
if (i == currentpage)
{
sb.append("<a href=\"?page=" + i + "\" class=\"current\" ><font color=\"red\">" + i + "</font></a> ");
}
else
{
if (i > (currentpage - prev - 1) && i < (currentpage + next + 1))
{
sb.append("<a href=\"?page=" + i + "\">" + i + "</a> ");
}
}
}
if (currentpage < pagecount - next)
sb.append("... <a href=\"?page=" + pagecount.tostring() + "\">" + pagecount.tostring() + "</a>");
if (currentpage < pagecount)
sb.append(" <a href=\"?page=" + (currentpage + 1).tostring() + "\">后一页</a>");
return sb.tostring();
}
复制代码 代码如下:
/// <summary>
/// 分页链接
/// </summary>
/// <param name="pagesize"></param>
/// <param name="recordcount"></param>
/// <param name="currentpage"></param>
/// <param name="prev">当前页前面显示的数量</param>
/// <param name="next">当前页后面显示的数量</param>
/// <returns></returns>
public string pagelink(int pagesize, int recordcount, int currentpage, int prev, int next)
{
int pagecount = recordcount % pagesize == 0 ? (recordcount / pagesize) : ((int)math.ceiling((double)recordcount / pagesize));
stringbuilder sb = new stringbuilder();
if (currentpage > 1 && recordcount > 1)
{
sb.append("<a href=\"?page=");
sb.append((currentpage - 1).tostring());
sb.append("\">前一页</a> ");
}
if (currentpage > prev + 1)
sb.append("<a href=\"?page=1\">1</a> ... ");
if (currentpage < prev)
next = next + prev - currentpage + 1;
if (next > pagecount - currentpage)
prev = prev + next - (pagecount - currentpage);
for (int i = 1; i <= pagecount; i++)
{
if (i == currentpage)
{
sb.append("<a href=\"?page=" + i + "\" class=\"current\" ><font color=\"red\">" + i + "</font></a> ");
}
else
{
if (i > (currentpage - prev - 1) && i < (currentpage + next + 1))
{
sb.append("<a href=\"?page=" + i + "\">" + i + "</a> ");
}
}
}
if (currentpage < pagecount - next)
sb.append("... <a href=\"?page=" + pagecount.tostring() + "\">" + pagecount.tostring() + "</a>");
if (currentpage < pagecount)
sb.append(" <a href=\"?page=" + (currentpage + 1).tostring() + "\">后一页</a>");
return sb.tostring();
}
下一篇: 详解Java实现负载均衡的几种算法代码
推荐阅读
-
asp.net 分页链接方法
-
asp.net 删除MFC单文档默认菜单栏的两种方法
-
IIS中ASP.NET连接SQL Server出错的解决方法
-
asp.net 分页显示数据表的数据的代码
-
asp.net GridView中超链接的使用(带参数)
-
asp.net下Repeater使用 AspNetPager分页控件
-
巧用ASP.NET预编译Web应用程序规避调用延迟的方法
-
ASP.NET性能优化之让浏览器缓存动态网页的方法
-
asp.net中用DataReader高效率分页
-
ASP.NET MVC运行出现Uncaught TypeError: Cannot set property __MVC_FormValidation of null的解决方法