-
类似baidu google分页页码效果的代码
以后做图片网站用过,现在只写出代码,其实没什么技术含量,只是最近工作不顺,心情稍差,思维有点懒惰,工作的时候需要抄过来用用OK,所才Post在此.
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
/**//// <summary>
/// 创建并显示分页器
/// </summary>
private void BuildPager(int totalRecords,int currentPage,int pageSize,int pid)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
int alter = 4 ;
int startPage = 1 ;
int endPage = currentPage + alter ;
int totalPages = this.CalculateTotalPages(totalRecords,pageSize) ;
![](/Images/OutliningIndicators/InBlock.gif)
if(currentPage > alter)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
startPage = currentPage - alter ;
}
![](/Images/OutliningIndicators/InBlock.gif)
if(endPage > totalPages)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
endPage = totalPages ;
}
![](/Images/OutliningIndicators/InBlock.gif)
string strTemp = @"<a href='PhotoList.aspx?pid={0}&pno={1}'>{2}</a> " ;
StringBuilder sb = new StringBuilder("") ;
if(currentPage != startPage)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
sb.Append( string.Format( strTemp , pid , 1 , "上一页" ) ) ;
}
![](/Images/OutliningIndicators/InBlock.gif)
for( int i = startPage ; i <= endPage ; i++ )
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if( currentPage == i )
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
sb.Append("<font color=red>" + i + "</font> ") ;
}
else
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
sb.Append( string.Format( strTemp , pid , i ,"[" + i + "]" ) ) ;
}
}
![](/Images/OutliningIndicators/InBlock.gif)
if(currentPage != endPage)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
sb.Append( string.Format( strTemp , pid , currentPage + 1 , "下一页") ) ;
}
![](/Images/OutliningIndicators/InBlock.gif)
this.ltlShowPager.Text = sb.ToString() ;
}
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
/**//// <summary>
/// 计算总页数
/// </summary>
/// <param name="totalRecords">总记录数</param>
/// <param name="pageSize">每页记录数</param>
private int CalculateTotalPages(int totalRecords, int pageSize)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
int totalPagesAvailable;
![](/Images/OutliningIndicators/InBlock.gif)
totalPagesAvailable = totalRecords / pageSize;
![](/Images/OutliningIndicators/InBlock.gif)
//由于C#的整形除法 会把所有余数舍入为0,所以需要判断是否需要加1
if ((totalRecords % pageSize) > 0)
totalPagesAvailable++;
![](/Images/OutliningIndicators/InBlock.gif)
return totalPagesAvailable;
}
-
相关阅读:
罗振宇 知识就是力量之怎样做一个不冲动的人
C++中stl的map
stl中顺序性容器,关联容器两者粗略解释
stl之容器、迭代器、算法几者之间的关系
mysql技术内幕之常规使用
essential c++ 第一章 array及vector相关使用
由函数clock想到的
编程获得CPU的主频
Markdown 基本语法
Future FutrueTask Callable类源码说明以及原理使用
-
原文地址:https://www.cnblogs.com/kwklover/p/381832.html
Copyright © 2020-2023
润新知