zoukankan
html css js c++ java
[Transfer]DataList 自定义分页 (C#)
Source:
http://www.cnblogs.com/youxia/archive/2006/08/14/476815.html
http://www.net0791.com/article/100997.htm
http://www.xker.com/Html/bcyy/net/2006_04_03_07_886_5.html
<%
@ Page Language
=
"
C#
"
%>
<%
@ Import Namespace
=
"
System.Data
"
%>
<%
@ Import Namespace
=
"
System.Data.OleDb
"
%>
<
Script Language
=
"
C#
"
Runat
=
"
Server
"
>
/**/
/*
Create By 飞刀
http://www.aspcn.com
2001-7-25 01:44
Support .Net Framework Beta 2
*/
OleDbConnection MyConn;
int
PageSize,RecordCount,PageCount,CurrentPage;
public
void
Page_Load(Object src,EventArgs e)
{
//
设定PageSize
PageSize
=
10
;
//
连接语句
string
MyConnString
=
"
Provider=Microsoft.Jet.OLEDB.4.0; Data Source=
"
+
Server.MapPath(
"
.
"
)
+
"
..\\DataBase\\db1.mdb;
"
;
MyConn
=
new
OleDbConnection(MyConnString);
MyConn.Open();
//
第一次请求执行
if
(
!
Page.IsPostBack)
{
ListBind();
CurrentPage
=
0
;
ViewState[
"
PageIndex
"
]
=
0
;
//
计算总共有多少记录
RecordCount
=
CalculateRecord();
lblRecordCount.Text
=
RecordCount.ToString();
//
计算总共有多少页
PageCount
=
RecordCount
/
PageSize;
lblPageCount.Text
=
PageCount.ToString();
ViewState[
"
PageCount
"
]
=
PageCount;
}
}
//
计算总共有多少条记录
public
int
CalculateRecord()
{
int
intCount;
string
strCount
=
"
select count(*) as co from Score
"
;
OleDbCommand MyComm
=
new
OleDbCommand(strCount,MyConn);
OleDbDataReader dr
=
MyComm.ExecuteReader();
if
(dr.Read())
{
intCount
=
Int32.Parse(dr[
"
co
"
].ToString());
}
else
{
intCount
=
0
;
}
dr.Close();
return
intCount;
}
ICollection CreateSource()
{
int
StartIndex;
//
设定导入的起终地址
StartIndex
=
CurrentPage
*
PageSize;
string
strSel
=
"
select * from Score
"
;
DataSet ds
=
new
DataSet();
OleDbDataAdapter MyAdapter
=
new
OleDbDataAdapter(strSel,MyConn);
MyAdapter.Fill(ds,StartIndex,PageSize,
"
Score
"
);
return
ds.Tables[
"
Score
"
].DefaultView;
}
public
void
ListBind()
{
score.DataSource
=
CreateSource();
score.DataBind();
lbnNextPage.Enabled
=
true
;
lbnPrevPage.Enabled
=
true
;
if
(CurrentPage
==
(PageCount
-
1
)) lbnNextPage.Enabled
=
false
;
if
(CurrentPage
==
0
) lbnPrevPage.Enabled
=
false
;
lblCurrentPage.Text
=
(CurrentPage
+
1
).ToString();
}
public
void
Page_OnClick(Object sender,CommandEventArgs e)
{
CurrentPage
=
(
int
)ViewState[
"
PageIndex
"
];
PageCount
=
(
int
)ViewState[
"
PageCount
"
];
string
cmd
=
e.CommandName;
//
判断cmd,以判定翻页方向
switch
(cmd)
{
case
"
next
"
:
if
(CurrentPage
<
(PageCount
-
1
)) CurrentPage
++
;
break
;
case
"
prev
"
:
if
(CurrentPage
>
0
) CurrentPage
--
;
break
;
}
ViewState[
"
PageIndex
"
]
=
CurrentPage;
ListBind();
}
</
script
>
<
html
>
<
head
>
<
title
></
title
>
</
head
>
<
body
>
<
form runat
=
"
server
"
>
共有
<
asp:Label id
=
"
lblRecordCount
"
ForeColor
=
"
red
"
runat
=
"
server
"
/>
条记录
当前为
<
asp:Label id
=
"
lblCurrentPage
"
ForeColor
=
"
red
"
runat
=
"
server
"
/>/<
asp:Label id
=
"
lblPageCount
"
ForeColor
=
"
red
"
runat
=
"
server
"
/>
页
<
asp:DataList id
=
"
score
"
runat
=
"
server
"
HeaderStyle
-
BackColor
=
"
#aaaadd
"
AlternatingItemStyle
-
BackColor
=
"
Gainsboro
"
EditItemStyle
-
BackColor
=
"
yellow
"
>
<
ItemTemplate
>
姓名:
<%
# DataBinder.Eval(Container.DataItem,
"
Name
"
)
%>
<
asp:LinkButton id
=
"
btnSelect
"
Text
=
"
编辑
"
CommandName
=
"
edit
"
runat
=
"
server
"
/>
</
ItemTemplate
>
</
asp:DataList
>
<
asp:LinkButton id
=
"
lbnPrevPage
"
Text
=
"
上一页
"
CommandName
=
"
prev
"
OnCommand
=
"
Page_OnClick
"
runat
=
"
server
"
/>
<
asp:LinkButton id
=
"
lbnNextPage
"
Text
=
"
下一页
"
CommandName
=
"
next
"
OnCommand
=
"
Page_OnClick
"
runat
=
"
server
"
/>
</
form
>
</
body
>
</
html
>
查看全文
相关阅读:
sc 使用
sql端点应用
今天面试笔试了一道SQL面试题,狠简单
指定域的名称或安全标识SID与该域的信任信息不一致
查询登陆时间间隔不超过5分钟的所有记录
sql打开xls
Android控件开发
android开发1【转】网络设备状态检测
google.maps Simple Polylines
Notification 使用详解(很全
原文地址:https://www.cnblogs.com/apiapia/p/655145.html
最新文章
【转】Win XP远程登录如何远程控制电脑(windows系列大体相同)的相关设置
SharePoint中的EventReceiver 之三 编写Event Handler
SharePoint中的EventReceiver 之四 为Content Type编写Event Handler
SynAttackProtect
SharePoint 2007中的三类Cache
如何创建强命名程序集, 如何查看强命名程序集的PublicKeyToken
ASP.NET的页面中对其他文件的引用
AD RMS与SharePoint 2007的集成的一些要点
PowerShell Cheat Sheet 1.0
SharePoint中的EventReceiver 之二 绑定Event Receiver到列表类型或列表实例
热门文章
TCP Chimney
使用 BasePage 来解决 GridView 执行 RenderControl 产生的错误
大连二级及二级以上医保定点医院名单
Web开发工具大集合——每个浏览器都有份的!
dos批处理选择菜单方法
EmEditor 显示匹配的多行的字符
vbs常用脚本大全,配有实例
Excel 的多进程使用,防止excel的误操作
ChangeStartMode 用法
批处理隐藏自身窗口
Copyright © 2011-2022 走看看