asp.net 分页链接方法

你的心应该保持这种模样,略带发力的紧张,不松懈,对待不定有坦然。损伤是承载,沉默是扩展。终结是新的开始。如此,我会为你的心产生敬意。

/// <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 rel="nofollow noopener noreferrer" href=\"?page=");
sb.Append((currentPage - 1).ToString());
sb.Append("\">前一页</a>");
}
if (currentPage > prev + 1)
sb.Append("<a rel="nofollow noopener noreferrer" 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 rel="nofollow noopener noreferrer" href=\"?page=" + i + "\" class=\"current\" ><font color=\"red\">" + i + "</font></a>");
}
else
{
if (i > (currentPage - prev - 1) && i < (currentPage + next + 1))
{
sb.Append("<a rel="nofollow noopener noreferrer" href=\"?page=" + i + "\">" + i + "</a>");
}
}
}
if (currentPage < pageCount - next)
sb.Append("...<a rel="nofollow noopener noreferrer" href=\"?page=" + pageCount.ToString() + "\">" + pageCount.ToString() + "</a>");
if (currentPage < pageCount)
sb.Append("<a rel="nofollow noopener noreferrer" href=\"?page=" + (currentPage + 1).ToString() + "\">后一页</a>");
return sb.ToString();
}

本文asp.net 分页链接方法到此结束。不为失败找理由,要为成功找方法。小编再次感谢大家对我们的支持!

您可能有感兴趣的文章
ASP.NET中Response.BufferOutput属性的使用技巧

ASP.NET轻量级MVC框架Nancy的基本用法

使用grpcui测试ASP.NET core的gRPC服务

ASP.NET Core中的对象池介绍

.NET集成ORM框架HiSql