zoukankan
html css js c++ java
一个简单的分页控件
using
System;
using
System.Web;
using
System.Web.UI.WebControls;
using
System.Text;
using
System.Drawing;
using
System.Web.UI.HtmlControls;
using
System.Web.UI;
using
System.ComponentModel;
namespace
KuKu
{
/**/
///
<summary>
///
Summary description for KuKuPager.
///
</summary>
public
class
KuKuPager:WebControl
{
//
背景图片
string
_backGroud;
//
页查询参数
string
_pageQurey;
//
首页编号
int
_firstPage
=
1
;
//
总共的记录数目
int
_totalRecord;
//
页面大小
int
_pageSize;
int
_pageIndex;
int
_totalPage;
public
KuKuPager()
{
}
protected
override
void
OnLoad(EventArgs e)
{
_pageIndex
=
_firstPage;
if
(HttpContext.Current.Request.QueryString[_pageQurey]
!=
null
)
{
_pageIndex
=
Convert.ToInt32(HttpContext.Current.Request.QueryString[_pageQurey]);
}
if
(_pageSize
!=
0
)
{
if
(_totalRecord
%
_pageSize
==
0
)
{
_totalPage
=
_totalRecord
/
_pageSize;
}
else
{
_totalPage
=
_totalRecord
/
_pageSize
+
1
;
}
}
}
protected
override
void
Render(HtmlTextWriter writer)
{
string
first
=
"
<font face='webdings'>9</font>
"
;
string
previous
=
"
<font face='webdings'>7</font>
"
;
string
next
=
"
<font face='webdings'>8</font>
"
;
string
last
=
"
<font face='webdings'>:</font>
"
;
StringBuilder sb
=
new
StringBuilder();
sb.Append(
"
<div style='float:left'>
"
);
sb.Append(
"
<font class='t3' style='font-family:Courier New;font-size:12px'>
"
);
if
(PageIndex
==
1
)
{
sb.Append(first
+
"
"
+
previous
+
"
<b>
"
);
}
else
{
sb.Append(
"
<a href='
"
+
BuildNewPageUrl(
this
.FirstPageNum)
+
"
'>
"
+
first
+
"
</a>
"
);
sb.Append(
"
<a href='
"
+
BuildNewPageUrl(
this
.PageIndex
-
1
)
+
"
'>
"
+
previous
+
"
</a> <b>
"
);
}
int
j
=
1
;
if
(PageIndex
-
5
>=
1
)
{
j
=
PageIndex
-
5
;
}
int
k
=
TotalPage;
if
(PageIndex
+
5
<=
TotalPage)
{
k
=
PageIndex
+
5
;
}
if
(j
>
1
)
{
sb.Append(
"
<a href='
"
+
BuildNewPageUrl(
this
.FirstPageNum)
+
"
'>1</a>
"
);
}
for
(
int
i
=
j;i
<
k
+
1
;i
++
)
{
if
(PageIndex
==
i)
{
sb.Append(
"
<span class='t2'>
"
+
i
+
"
</span>
"
);
}
else
{
sb.Append(
"
<a href='
"
+
BuildNewPageUrl(i
-
this
.FirstPageNum
+
1
)
+
"
'>
"
+
i
+
"
</a>
"
);
}
}
if
(TotalPage
>
k)
{
sb.Append(
"
<a href='
"
+
BuildNewPageUrl(
this
.TotalPage)
+
"
'>
"
+
TotalPage
+
"
</a>
"
);
}
if
(PageIndex
==
TotalPage)
{
sb.Append(
"
</b>
"
+
next
+
"
"
+
last);
}
else
{
sb.Append(
"
</b><a href='
"
+
BuildNewPageUrl(
this
.PageIndex
+
1
)
+
"
'>
"
+
next
+
"
</a>
"
);
sb.Append(
"
<a href='
"
+
BuildNewPageUrl(
this
.TotalPage)
+
"
'>
"
+
last
+
"
</a>
"
);
}
sb.Append(
"
</font></div>
"
);
sb.Append(
"
<div style='float:right'>
"
);
sb.Append(
"
[总记录数:<span class='pagerRight'>
"
+
TotalRecord
+
"
</span>]
"
);
sb.Append(
"
[每页:<span class='pagerRight'>
"
+
PageSize
+
"
</span>]
"
);
sb.Append(
"
[总页数:<span class='pagerRight'>
"
+
TotalPage
+
"
</span>]
"
);
sb.Append(
"
[当前为第<span class='pagerRight'>
"
+
PageIndex
+
"
</span>页]</div>
"
);
writer.WriteLine(sb.ToString());
}
/**/
///
<summary>
///
当前页面的路径
///
</summary>
string
BuildNewPageUrl(
int
page)
{
HttpRequest request
=
HttpContext.Current.Request;
//
页面没有参数
if
(request.QueryString.Count
==
0
)
{
return
request.Url.PathAndQuery
+
"
?
"
+
this
.PageQuery
+
"
=
"
+
page;
}
//
如果当前页面没有页面查询参数,说明为第一页
else
if
(request.QueryString[
this
.PageQuery]
==
null
)
{
return
request.Url.PathAndQuery
+
"
&
"
+
this
.PageQuery
+
"
=
"
+
page;
}
else
{
return
request.Url.PathAndQuery.Replace(
this
.PageQuery
+
"
=
"
+
request.QueryString[
this
.PageQuery],
this
.PageQuery
+
"
=
"
+
page.ToString());
}
}
/**/
///
<summary>
///
获取或者设置KuKuPager的背景图片
///
</summary>
public
string
BackGround
{
get
{
return
_backGroud;
}
set
{
_backGroud
=
value;
}
}
/**/
///
<summary>
///
获取或者设置KuKuPager的页查询参数
///
</summary>
public
string
PageQuery
{
get
{
return
_pageQurey;
}
set
{
_pageQurey
=
value;
}
}
/**/
///
<summary>
///
获取或者设置KuKuPager首页编号
///
</summary>
public
int
FirstPageNum
{
get
{
return
_firstPage;
}
set
{
_firstPage
=
value;
}
}
/**/
///
<summary>
///
获取或者设置KuKuPager页面大小
///
</summary>
public
int
PageSize
{
get
{
return
_pageSize;
}
set
{
_pageSize
=
value;
}
}
/**/
///
<summary>
///
获取或者设置KuKuPager总共的记录数目
///
</summary>
public
int
TotalRecord
{
get
{
return
_totalRecord;
}
set
{
_totalRecord
=
value;
}
}
public
int
PageIndex
{
get
{
return
_pageIndex;
}
}
/**/
///
<summary>
///
获取或者设置KuKuPager总页数
///
</summary>
public
int
TotalPage
{
get
{
return
_totalPage;
}
}
}
}
作者:
jillzhang
出处:
http://jillzhang.cnblogs.com/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
查看全文
相关阅读:
Jemeter编写脚本(五类常见请求)
正则表达式-问号的四种用法
Python正则表达式操作指南(转)
Python文件和目录操作方法大全(含实例)
Python os.walk() 方法
Python文件和流
Python pip常用指令
Windows7下配置JMeter安装环境
postman进行http接口测试
递归Python文件目录操作
原文地址:https://www.cnblogs.com/jillzhang/p/359600.html
最新文章
模块基础
字符串格式化的2种方式
生成器、迭代器、递归
python 多层装饰器
python 装饰器简介
python内置函数(4)
内置函数(3)
内置函数(2)
python 的内置函数(1)
python 的文件操作。
热门文章
Codeforces Round #211 (Div. 2)
poj 1716 1201 差分约束 SPFA
poj 2942 Knights of the Round Table Tarjan求点双联通分量+黑白染色二分图判断
记新生赛(2013多校第二场题解)
POJ 2186 Popular Cows
多校7
2013 Multi-University Training Contest 6
2013 ACM/ICPC 杭州邀请赛重现
2013 Multi-University Training Contest 5
Codeforces #191(Div.2)解题报告
Copyright © 2011-2022 走看看