博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C#页码导航显示及算法
阅读量:6699 次
发布时间:2019-06-25

本文共 4469 字,大约阅读时间需要 14 分钟。

页码导航,先看显示效果:

算法要求:

1、页数小于等于1时不显示;

2、页数大于10时,自动缩短。

 

具体代码如下:

///         /// 获取分页导航        ///         /// 页码        /// 页数        /// 链接        /// 
HTML代码
private string GePageNavgation(int intPageIndex, int intPageCount, string strUrl) { StringBuilder sb = new StringBuilder("
"); if (intPageCount > 1) { //页码显示 if (intPageIndex == 1) { sb.Append("
< 上一页"); } else if (intPageIndex > 1) { sb.Append("
< 上一页"); } bool Dot1 = false, Dot2 = false; for (int i = 1; i <= intPageCount; i++) { if (i == intPageIndex) { sb.Append("
" + intPageIndex.ToString() + ""); continue; } if (i <= 3) { sb.Append("
" + i.ToString() + ""); continue; } if (intPageIndex > 7) { if (!Dot1) { sb.Append("
..."); Dot1 = true; } } if (i == intPageIndex - 3) { sb.Append("
" + i.ToString() + ""); continue; } if (i == intPageIndex - 2) { sb.Append("
" + i.ToString() + ""); continue; } if (i == intPageIndex - 1) { sb.Append("
" + i.ToString() + ""); continue; } if (i == intPageIndex + 1) { sb.Append("
" + i.ToString() + ""); continue; } if (i == intPageIndex + 2) { sb.Append("
" + i.ToString() + ""); continue; } if (i == intPageIndex + 3) { sb.Append("
" + i.ToString() + ""); continue; } if ((intPageCount - intPageIndex) > 6 && i > intPageIndex + 3) { if (!Dot2) { sb.Append("
..."); Dot2 = true; } } if (i > intPageCount - 3) { sb.Append("
" + i.ToString() + ""); continue; } } if (intPageIndex == intPageCount) { sb.Append("
下一页 >"); } else if (intPageIndex + 1 <= intPageCount) { sb.Append("
下一页 >"); } } sb.Append("
"); return sb.ToString(); }

CSS样式:

.div_pagenavgation{
margin-top:5px; line-height:20px; float:right;}.div_pagenavgation a{
float:left; text-decoration:none; color:#06F; margin-left:5px; padding-left:5px; padding-right:5px; height:20px; text-align:center; display:block; border:1px #CCC solid;}.div_pagenavgation .dotted{
float:left; }.div_pagenavgation .current{
float:left; margin-left:5px; padding-left:5px; padding-right:5px; height:20px; text-align:center; display:block; border:1px #CCC solid ; background-color:#0080C0; color:#FFF;}.div_pagenavgation .disabled{
float:left; margin-left:5px; padding-left:5px; padding-right:5px; height:20px; text-align:center; display:block; border:1px #CCC solid; color:#CCC;}

 

产生的HTML如下:

 

 

说明:很久前赶工完成,基本能够实现要求,没有经过仔细优化,谁优化了再回复看看!

 

 

 

 

转载于:https://www.cnblogs.com/zonx/archive/2012/12/14/2818476.html

你可能感兴趣的文章
安永:第19届全球信息安全调查报告
查看>>
Linux的硬链接和软链接
查看>>
eclipse maven配置注意
查看>>
Event ID 2042: It has been too long since this machine replicated域控超过墓碑期未进行复制...
查看>>
mysql怎么查看表的储存引擎
查看>>
如何对List<Map> 进行排序
查看>>
Zabbix 全新安装教程 入门使用教程
查看>>
String的split小记
查看>>
SVN 查看版本历史时Item is not readable (show log)
查看>>
linux scp 命令详解
查看>>
Windows编程 第六回 又见设备描述表
查看>>
piped线程通信
查看>>
java.sql.SQLException: 流已被关闭
查看>>
html的meta集合
查看>>
解决跨域put请求
查看>>
菜鸟学Linux 第053篇笔记 Section 3
查看>>
支付宝预授权冻结
查看>>
Oracle性能优化 之 共享池
查看>>
Log4j入门
查看>>
C#学习常用命名空间【1000】---System.Reflection 之MethodBase(方法库类)
查看>>