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
;
}
}
查看全文
相关阅读:
form提交上传图片
存储过程分页
表格隔行换色效果
C#获取本地局域网IP
sql 拆分字符串并循环取值
sql日期转换
HDU 4858
HDU 1199
URAL 1306
Codeforces Round #288 (Div. 2)
原文地址:https://www.cnblogs.com/cancer_xu/p/1607122.html
最新文章
>xx.hbm.xml的一些简单配置
express框架结合jade模板引擎使用
express框架结合ejs模板引擎使用
express框架实现承载静态页面的能力
ejs模板引擎
如何把涉及到回调函数的一个异步过程变成同步过程
NodeJs异步的执行过程
NodeJs实现客户端登陆
bootstrap使用总结
angularJS1笔记-(20)-模块化加载机制seajs
热门文章
angularJS1笔记-(19)-angular异步加载包的方式
$route路由
$timeout()定时器
AngularJS中的http服务的简单用法
小知识
sass和less、stylus语法(2)
Sass和Less、Stylus的转译和语法(1)
Sass、Less和Stylus
javascript一些小的注意点
Angular常犯的错误
Copyright © 2011-2022 走看看