栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > asp

C#页码导航显示及算法实现代码

asp 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C#页码导航显示及算法实现代码

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

算法要求
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如下:
复制代码 代码如下:

< 上一页
1
2
3
...
9
10
11
12
13
14
15
...
27
28
29
下一页 >


说明:很久前赶工完成,基本能够实现要求,没有经过仔细优化,谁优化了再回复看看!
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/58207.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号