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/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
查看全文
相关阅读:
html文件引用本地js文件出现跨域问题的解决方案
【移动端】cordova 更改app的图标、名字、加载画面以及强制横竖屏
thinkphp5.0返回插入数据id
ThinkPHP5 隐藏index.php问题
密码强度正则表达式 – 必须包含大写字母,小写字母和数字,至少8个字符等
php实现微信分享朋友圈
HTML Input 表单校验之datatype
TP5:使用了INPUT函数来接收参数了,还需再过滤SQL注入吗
大商创微信公众号微信支付失败报错
$GLOBALS — 引用全局作用域中可用的全部变量
原文地址:https://www.cnblogs.com/jillzhang/p/359600.html
最新文章
ubuntu安装python的mysqlclient
创建docekr容器,进入docker容器
vue-router query和params传参(接收参数)$router $route的区别
vue-router路由动态传参query和params的区别
vue-计算属性和侦听属性
vue路由的两种模式,hash与history
npm(你怕吗) 全局安装与本地安装、开发依赖和生产依赖
CSS文本超过2行省略号(...)显示
js取整方法
js获取某一天是今年的第多少周
热门文章
webpack中output之path和publicPath详解
Ext中statics()与self
【Vue源码】简单实现Vue的双向数据绑定:Object.defineProperty和Proxy
【Vue源码】Object.defineProperty与Proxy
【Vue】vuejs中拖动改变元素宽度实现宽度自适应大小
【Vue】父组件监听到子组件的生命周期
【Vue】 组件通信之$attrs、$listeners
CSS 子绝(position:absolute;)父相(position:relative)
JS中的offsetWidth/offsetHeight/offsetTop/offsetLeft、clientWidth/clientHeight/clientTop/clientLeft、scrollWidth/scrollHeight/scrollTop/scrollLeft
【Vue】provide/inject实现组件通信
Copyright © 2011-2022 走看看