会员
周边
众包
新闻
博问
闪存
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
上善若水,水善利万物而不争
博客园
首页
新随笔
联系
订阅
管理
封装DataList分页
封装完成后效果如上图.
部分代码如下:
/**/
///
<summary>
///
首页
///
</summary>
LinkButton First
=
new
LinkButton();
/**/
///
<summary>
///
上一页
///
</summary>
LinkButton Prev
=
new
LinkButton();
/**/
///
<summary>
///
下一页
///
</summary>
LinkButton Next
=
new
LinkButton();
/**/
///
<summary>
///
末页
///
</summary>
LinkButton Last
=
new
LinkButton();
//
保存原有旧页的记录数
int
oldPageSize
=
PageSize;
if
(ViewState[
"
GridViewPage
"
]
==
null
)
{
ViewState[
"
GridViewPage
"
]
=
FirstPage;
}
Table PageTable
=
new
Table();
TableRow tr1
=
new
TableRow();
//
新加行
TableCell tc1
=
new
TableCell();
//
分页信息列
TableCell tc2
=
new
TableCell();
//
分页按钮信息列
tc2.Attributes.Add(
"
align
"
,
"
right
"
);
int
p
=
PageIndex
+
1
;
tc1.Controls.Add(
new
LiteralControl(
"
页数:<font color='red'>
"
+
p.ToString()
+
"
</font>/
"
+
PageCount.ToString()));
tc1.Controls.Add(
new
LiteralControl(
"
"
));
tc1.Controls.Add(
new
LiteralControl(
"
共
"
+
ViewState[
"
RecortCount
"
].ToString()
+
"
条记录 每页
"
+
PageSize.ToString()
+
"
条记录
"
));
tc1.Attributes.Add(
"
align
"
,
"
left
"
);
tc1.Attributes.Add(
"
width
"
,
"
295px
"
);
First.Text
=
"
<font face='webdings'>9</font>
"
;
First.CommandName
=
"
Page
"
;
First.CommandArgument
=
"
First
"
;
First.Font.Underline
=
false
;
First.ToolTip
=
"
首页
"
;
Prev.Text
=
"
<font face='webdings'>3</font>
"
;
Prev.CommandName
=
"
Page
"
;
Prev.CommandArgument
=
"
Prev
"
;
Prev.Font.Underline
=
false
;
Prev.ToolTip
=
"
上一页
"
;
Next.Text
=
"
<font face=\
"
webdings\
"
>4</font>
"
;
Next.CommandName
=
"
Page
"
;
Next.CommandArgument
=
"
Next
"
;
Next.Font.Underline
=
false
;
Next.ToolTip
=
"
下一页
"
;
Last.Text
=
"
<font face='webdings'>:</font>
"
;
Last.CommandName
=
"
Page
"
;
Last.CommandArgument
=
"
Last
"
;
Last.Font.Underline
=
false
;
Last.ToolTip
=
"
末页
"
;
First.Click
+=
new
EventHandler(lbN_Click);
Prev.Click
+=
new
EventHandler(lbN_Click);
Next.Click
+=
new
EventHandler(lbN_Click);
Last.Click
+=
new
EventHandler(lbN_Click);
if
((PageCount
-
FirstPage)
<
_ShowPageCount)
{
FirstPage
=
PageCount
-
_ShowPageCount;
}
if
(FirstPage
>
PageIndex)
{
FirstPage
=
PageIndex
-
8
;
//
FirstPage = PageIndex ;
}
if
(PageIndex
<
_ShowPageCount
-
1
)
{
FirstPage
=
1
;
}
if
(
this
.PageIndex
<=
0
)
//
第一页
{
tc2.Controls.Add(
new
LiteralControl(
"
<font color='GRay'>
"
+
First.Text
+
"
</font>
"
));
tc2.Controls.Add(
new
LiteralControl(
"
<font color='GRay'>
"
+
Prev.Text
+
"
</font>
"
));
}
else
{
tc2.Controls.Add(First);
tc2.Controls.Add(
new
LiteralControl(
"
"
));
tc2.Controls.Add(Prev);
tc2.Controls.Add(
new
LiteralControl(
"
"
));
}
if
(PageIndex
>=
FirstPage
+
_ShowPageCount
-
1
)
{
FirstPage
=
PageIndex;
//
FirstPage = PageIndex;
if
(PageCount
-
FirstPage
<
_ShowPageCount)
{
FirstPage
=
PageCount
-
_ShowPageCount;
}
}
if
(PageIndex
==
FirstPage
-
1
)
{
FirstPage
=
PageIndex
-
_ShowPageCount
+
2
;
if
(FirstPage
<=
0
)
{
FirstPage
=
1
;
}
}
if
(PageIndex
<=
0
)
{
FirstPage
=
1
;
}
ViewState[
"
GridViewPage
"
]
=
FirstPage;
for
(
int
i
=
FirstPage
-
1
; i
<=
PageCount; i
++
)
{
if
(i
>=
FirstPage
&&
i
<=
FirstPage
+
_ShowPageCount)
{
if
(i
==
PageIndex
+
1
)
{
tc2.Controls.Add(
new
LiteralControl(
"
<font color='red'><b>
"
+
i.ToString()
+
"
</b></font>
"
));
}
else
{
LinkButton lbN
=
new
LinkButton();
if
((i
==
FirstPage
+
_ShowPageCount
||
i
==
FirstPage)
&&
i
!=
1
&&
i
!=
PageCount)
{
lbN.Text
=
"
.
"
;
}
else
{
lbN.Text
=
i.ToString();
}
lbN.Click
+=
new
EventHandler(lbN_Click);
lbN.CommandArgument
=
i.ToString();
lbN.CommandName
=
"
PageNum
"
;
lbN.ToolTip
=
"
第
"
+
i.ToString()
+
"
页
"
;
tc2.Controls.Add(lbN);
tc2.Controls.Add(
new
LiteralControl(
"
"
));
}
}
else
{
continue
;
}
}
if
(
this
.PageIndex
>=
PageCount
-
1
)
//
最后一页
{
tc2.Controls.Add(
new
LiteralControl(
"
<font color='GRay'>
"
+
Next.Text
+
"
</font>
"
));
tc2.Controls.Add(
new
LiteralControl(
"
<font color='GRay'>
"
+
Last.Text
+
"
</font>
"
));
}
else
{
tc2.Controls.Add(Next);
tc2.Controls.Add(
new
LiteralControl(
"
"
));
tc2.Controls.Add(Last);
}
tr1.Cells.Add(tc1);
tr1.Cells.Add(tc2);
PageTable.Rows.Add(tr1);
PageTable.Attributes.Add(
"
width
"
,
"
100%
"
);
PageTable.BorderWidth
=
0
;
PageTable.CellPadding
=
0
;
PageTable.CellSpacing
=
0
;
return
PageTable;
使用方法,在Page_Load中加入如下绑定代码,即可:
if (!IsPostBack)
{
ThsDataList1.DataBind("select * from jobs");
}
posted @
2007-01-08 19:35
simplay
阅读(
1401
) 评论(
15
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部
公告