分页算法
public string RenderToHTML()
{
Check();
StringBuilder sb = new StringBuilder();
//double tempCount = (TotalCount+(0.0) )/ PageSize;
//int pageCount = (int)Math.Ceiling(tempCount);
int visibleStart = CurrentPageIndex - MaxPageCount / 2;
if (visibleStart<1)//6还是没区别
{
visibleStart = 1;
}
int visibleEnd = visibleStart + MaxPageCount;
if (visibleEnd > PageCount)
{
visibleEnd = PageCount;
}
if (CurrentPageIndex>1)
{
sb.Append(GetPageLink(1,"首页"));
sb.Append(GetPageLink(CurrentPageIndex-1,"上一页"));
}
else
{
sb.Append("<span>首页</span>");
sb.Append("<span>上一页</span>");
}
for (int i = visibleStart; i <=visibleEnd; i++)
{
if (i==CurrentPageIndex)
{
sb.Append("<span>").Append(i).Append("</span>");
}
else
{
sb.Append(GetPageLink(i,i.ToString()));
}
}
if (CurrentPageIndex < PageCount)
{
sb.Append(GetPageLink(CurrentPageIndex+1,"下一页"));
sb.Append(GetPageLink(PageCount, "末页"));
}
else
{
sb.Append("<span>下一页</span>");
sb.Append("<span>末页</span>");
}
return sb.ToString();
}
{
Check();
StringBuilder sb = new StringBuilder();
//double tempCount = (TotalCount+(0.0) )/ PageSize;
//int pageCount = (int)Math.Ceiling(tempCount);
int visibleStart = CurrentPageIndex - MaxPageCount / 2;
if (visibleStart<1)//6还是没区别
{
visibleStart = 1;
}
int visibleEnd = visibleStart + MaxPageCount;
if (visibleEnd > PageCount)
{
visibleEnd = PageCount;
}
if (CurrentPageIndex>1)
{
sb.Append(GetPageLink(1,"首页"));
sb.Append(GetPageLink(CurrentPageIndex-1,"上一页"));
}
else
{
sb.Append("<span>首页</span>");
sb.Append("<span>上一页</span>");
}
for (int i = visibleStart; i <=visibleEnd; i++)
{
if (i==CurrentPageIndex)
{
sb.Append("<span>").Append(i).Append("</span>");
}
else
{
sb.Append(GetPageLink(i,i.ToString()));
}
}
if (CurrentPageIndex < PageCount)
{
sb.Append(GetPageLink(CurrentPageIndex+1,"下一页"));
sb.Append(GetPageLink(PageCount, "末页"));
}
else
{
sb.Append("<span>下一页</span>");
sb.Append("<span>末页</span>");
}
return sb.ToString();
}
作者:Bober Song
出处:http://bober.cnblogs.com/
CARE健康网: http://www.aicareyou.com/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
出处:http://bober.cnblogs.com/
CARE健康网: http://www.aicareyou.com/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。