zoukankan
html css js c++ java
Pagination 分页类
public
class
Pagination
{
/**/
///
<summary>
///
页码显示
///
</summary>
///
<param name="curp">
当前页
</param>
///
<param name="pagecount">
总页数
</param>
///
<param name="maxcount">
最大显示页码行数
</param>
///
<param name="leftstr">
目标URL地址页码标记左边字符串
</param>
///
<param name="rightstr">
目标URL地址页码标记右边字符串
</param>
///
<returns>
页码字符串
</returns>
public
static
string
Show(
int
curp,
int
pagecount,
int
maxcount,
string
leftstr,
string
rightstr)
{
StringBuilder str
=
new
StringBuilder();
int
leftMin, RightMax;
if
(maxcount
%
2
==
0
)
{
leftMin
=
curp
-
intplus(maxcount);
RightMax
=
curp
+
intplus(maxcount)
+
1
;
}
else
{
leftMin
=
curp
-
intplus(maxcount);
RightMax
=
curp
+
intplus(maxcount);
}
if
(leftMin
<
2
)
leftMin
=
1
;
if
(RightMax
>
pagecount)
RightMax
=
pagecount;
if
(curp
<
intplus(maxcount)
&&
pagecount
>=
maxcount)
{
leftMin
=
1
;
RightMax
=
maxcount;
}
if
(leftMin
>
2
)
str.Append(
"
<a class=\
"
page\
"
href=\
""
+ leftstr +
"
1
"
+ rightstr +
"
\
"
title=\
"
第1页\
"
>1</a><a class=\
"
around\
"
href=\
""
+ leftstr + (curp - 1).ToString() + rightstr +
"
\
"
title=\
"
上一页\
"
><<</a>
"
);
if
(leftMin
==
2
)
str.Append(
"
<a class=\
"
page\
"
href=\
""
+ leftstr +
"
1
"
+ rightstr +
"
\
"
title=\
"
第1页\
"
>1</a>
"
);
for
(
int
i
=
leftMin; i
<=
RightMax; i
++
)
{
if
(i
==
curp)
str.Append(
"
<a class=\
"
pagenow\
"
>
"
+
i.ToString()
+
"
</a>
"
);
else
str.Append(
"
<a class=\
"
page\
"
href=\
""
+ leftstr + i.ToString() + rightstr +
"
\
"
title=\
"
第
"
+ i.ToString() +
"
页\
"
>
"
+
i.ToString()
+
"
</a>
"
);
}
if
(RightMax
<
pagecount
-
1
)
str.Append(
"
<a class=\
"
around\
"
href=\
""
+ leftstr + (curp + 1).ToString() + rightstr +
"
\
"
title=\
"
下一页\
"
>>></a><a class=\
"
page\
"
href=\
""
+ leftstr + pagecount.ToString() + rightstr +
"
\
"
title=\
"
第
"
+ pagecount.ToString() +
"
页\
"
>
"
+
pagecount.ToString()
+
"
</a>
"
);
if
(RightMax
==
pagecount
-
1
)
str.Append(
"
<a class=\
"
page\
"
href=\
""
+ leftstr + pagecount.ToString() + rightstr +
"
\
"
title=\
"
第
"
+ pagecount.ToString() +
"
页\
"
>
"
+
pagecount.ToString()
+
"
</a>
"
);
return
str.ToString();
}
/**/
///
<summary>
///
show page numbers: for long article.
///
</summary>
///
<param name="curp">
当前页
</param>
///
<param name="pagecount">
总页数
</param>
///
<param name="maxcount">
最大显示页码行数
</param>
///
<param name="leftstr">
目标URL地址页码标记左边字符串
</param>
///
<param name="rightstr">
目标URL地址页码标记右边字符串
</param>
///
<returns>
页码字符串
</returns>
public
static
string
Show2(
int
curp,
int
pagecount,
int
maxcount,
string
leftstr,
string
rightstr)
{
StringBuilder str
=
new
StringBuilder();
int
leftMin, RightMax;
if
(maxcount
%
2
==
0
)
{
leftMin
=
curp
-
intplus(maxcount);
RightMax
=
curp
+
intplus(maxcount)
+
1
;
}
else
{
leftMin
=
curp
-
intplus(maxcount);
RightMax
=
curp
+
intplus(maxcount);
}
if
(leftMin
<
2
)
leftMin
=
1
;
if
(RightMax
>
pagecount)
RightMax
=
pagecount;
if
(curp
<
intplus(maxcount)
&&
pagecount
>=
maxcount)
{
leftMin
=
1
;
RightMax
=
maxcount;
}
//
左侧
if
(curp
==
1
)
str.Append(
"
<a class=\
"
pagenow\
"
>上一页</a>
"
);
else
{
if
(curp
>
2
)
str.Append(
"
<a href=\
""
+ leftstr +
"
-
"
+ (curp - 1) + rightstr +
"
\
"
class=\
"
page\
"
>上一页</a>
"
);
else
str.Append(
"
<a href=\
""
+ leftstr + rightstr +
"
\
"
class=\
"
page\
"
>上一页</a>
"
);
}
if
(leftMin
>
2
)
str.Append(
"
<a class=\
"
page\
"
href=\
""
+ leftstr + rightstr +
"
\
"
title=\
"
第1页\
"
>1</a><a class=\
"
around\
"
href=\
""
+ leftstr +
"
-
"
+ (curp - 1).ToString() + rightstr +
"
\
"
title=\
"
上一页\
"
>‹‹</a>
"
);
if
(leftMin
==
2
)
str.Append(
"
<a class=\
"
page\
"
href=\
""
+ leftstr + rightstr +
"
\
"
title=\
"
第1页\
"
>1</a>
"
);
//
中间
for
(
int
i
=
leftMin; i
<=
RightMax; i
++
)
{
if
(i
==
curp)
str.Append(
"
<a class=\
"
pagenow\
"
>
"
+
i.ToString()
+
"
</a>
"
);
else
{
if
(i
>
1
)
str.Append(
"
<a class=\
"
page\
"
href=\
""
+ leftstr +
"
-
"
+ i.ToString() + rightstr +
"
\
"
title=\
"
第
"
+ i.ToString() +
"
页\
"
>
"
+
i.ToString()
+
"
</a>
"
);
else
str.Append(
"
<a class=\
"
page\
"
href=\
""
+ leftstr + rightstr +
"
\
"
title=\
"
第
"
+ i.ToString() +
"
页\
"
>
"
+
i.ToString()
+
"
</a>
"
);
}
}
//
右侧
if
(RightMax
<
pagecount
-
1
)
str.Append(
"
<a class=\
"
around\
"
href=\
""
+ leftstr +
"
-
"
+(curp + 1).ToString() + rightstr +
"
\
"
title=\
"
下一页\
"
>››</a><a class=\
"
page\
"
href=\
""
+ leftstr +
"
-
"
+pagecount.ToString() + rightstr +
"
\
"
title=\
"
第
"
+ pagecount.ToString() +
"
页\
"
>
"
+
pagecount.ToString()
+
"
</a>
"
);
if
(RightMax
==
pagecount
-
1
)
str.Append(
"
<a class=\
"
page\
"
href=\
""
+ leftstr +
"
-
"
+ pagecount.ToString() + rightstr +
"
\
"
title=\
"
第
"
+ pagecount.ToString() +
"
页\
"
>
"
+
pagecount.ToString()
+
"
</a>
"
);
if
(curp
==
pagecount)
str.Append(
"
<a class=\
"
pagenow\
"
>下一页</a>
"
);
else
str.Append(
"
<a href=\
""
+ leftstr +
"
-
"
+ (curp + 1) + rightstr +
"
\
"
class=\
"
page\
"
>下一页</a>
"
);
return
str.ToString();
}
/**/
///
<summary>
///
取得数除以2得数的整数部份
///
</summary>
///
<param name="i">
被2除的整数
</param>
///
<returns></returns>
public
static
int
intplus(
int
i)
{
if
(i
%
2
==
0
)
return
i
/
2
;
else
return
(i
-
1
)
/
2
;
}
}
查看全文
相关阅读:
如何解决WEB应用中文乱码问题
js获取指定格式的时间字符串
js 实现 Base64 编码的相互转换
Sql Server 与 MySql 在使用 update inner join 时的区别
VMware12创建新的虚拟机及设置硬件环境
Sql Server 中使用日期遍历
Linux 添加定时任务,crontab -e 命令与直接编辑 /etc/crontab 文件
mysql 中 max_allowed_packet 查询和修改
eclipse编译项目:Java @Override 注解报错的解决方法
eclipse启动项目报错:java.lang.ClassNotFoundException: ContextLoaderListener
原文地址:https://www.cnblogs.com/cancer_xu/p/1607122.html
最新文章
PHP开发api接口安全验证
安装CAS
jira开发,开启邮件通知
组织机构树数据库表设计
jira ao UpgradeTask
深入理解java虚拟机-01 走进java
深入理解java虚拟机-00
PowerMockRunner和ActiveObjectsJUnitRunner
easyui表格,单元格合并
idea使用
热门文章
python开发环境搭建
用VS2015编译sqlcipher
浮点型数据的比较
zlib库VS2015编译步骤
黑群晖虚拟机安装步骤记录
一种可扩展的表达式解析及计算方法
boost编译随笔
使用WinInet实现HTTP站点访问
xcode7中使用cocos2d-x3.8的webview控件
修改XCode默认工程为使用Xib
Copyright © 2011-2022 走看看