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
>
查看全文
相关阅读:
Sublime 下配置vim模式 + VintageEx-master下载地址
Potplayer快捷键
Failed to fetch URl https://dl-ssl.google.com/android/repository/addo Android SDK更新以及ADT更新出现问题的解决办法
最快速的Android开发环境搭建ADT-Bundle及Hello World
Android 开发环境下载地址 -- 百度网盘 adt-bundle android-studio sdk adt 下载
X-Mirage苹果屏幕录制工具7天试用期破解 imsoft.cnblogs
玩转博客园的心路总结
玩转博客园的5个小技巧
五个对你有用的Everything搜索技巧
PS如何批量处理图片
原文地址:https://www.cnblogs.com/apiapia/p/655145.html
最新文章
〖Linux〗不知谁写的,很实用的Linux命令
〖Fedora〗设置Fedora静态ip地址
〖Qt编程〗Qt编程中的各种数据类型的相互转换
〖QT编程〗在Qt编程中使用/显示中文编码
〖Linux〗通过USB连接,共享Linux上的网络,使用Android手机上网。
〖Linux〗使用root权限,telnet登录开发板
【Linux】(2013-7-19)配置tftp与开发板传送文件
〖C语言〗C语言一个函数传递无限制多参数(不确定参数函数)的方法
〖C++〗string2int把字符串转换成int的函数
unity, 使导入的材质名与3dmax中一致
热门文章
alpha预乘
unity, inspector listview
unity,List元素第一个成员最好是string类型
unity, 不要change Default sharedMaterial
unity, RT .DiscardContents ()导致android上RT不显示
unity, destroy gameObject & destroy all children
unity, SkinnedMeshRenderer.bones[i]不能直接赋值
unity, public+[HideInInspector] vs private
unity, 获取mesh名称
Sublime配置VI插件后 快捷键总结
Copyright © 2011-2022 走看看