当前位置:编程学习 > C#/ASP.NET >>

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 href=>sb.Append((currentPage - 1).ToString());
sb.Append("\">前一页</a> ");
}
if (currentPage > prev + 1)
sb.Append("<a href=>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=>}
else
{
if (i > (currentPage - prev - 1) && i < (currentPage + next + 1))
{
sb.Append("<a href=>}
}
}
if (currentPage < pageCount - next)
sb.Append("... <a href=>if (currentPage < pageCount)
sb.Append(" <a href=>return sb.ToString();
}

上一个:asp.net 2.0里也可以用JSON的使用方法
下一个:一个简答的Access下的分页asp.net代码

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,