博客
关于我
强烈建议你试试无所不能的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

你可能感兴趣的文章
Python的安装和详细配置(转)
查看>>
FloatingActionButton
查看>>
[再寄小读者之数学篇](2014-11-24 Abel 定理)
查看>>
iText导出pdf、word、图片
查看>>
android脚步---不同界面之间切换
查看>>
降压转换器 (Buck)
查看>>
Wami Map Project – 开源的 OSM API 服务
查看>>
【BZOJ】2946: [Poi2000]公共串
查看>>
Java虚拟机工作原理具体解释
查看>>
Windows Store App JavaScript 开发:模板绑定
查看>>
关于RPG游戏结构撰写的相关探索上篇
查看>>
Spring – Sending E-Mail Via Gmail SMTP Server With MailSender--reference
查看>>
(转)ffmpeg资源一览
查看>>
jvm调优经验分享
查看>>
高速公路坐标高程计算软件3.3版本发布
查看>>
CF519 ABCD D. A and B and Interesting Substrings(map,好题)
查看>>
【转】Android开发之旅:环境搭建及HelloWorld
查看>>
qt creator 快捷键 (二)
查看>>
【分享】博客美化(3)为博客添加一个漂亮的分享按钮
查看>>
VS2010发布、打包安装程序
查看>>