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
>
查看全文
相关阅读:
Netty源码分析之ByteBuf引用计数
GitHub git push大文件失败(write error: Broken pipe)完美解决
Windows10 Docker安装详细教程
全面的Docker快速入门教程
十本你不容错过的Docker入门到精通书籍推荐
CentOS 8.4安装Docker
postgres之一条sql查询总数及部分数据
neo4j相关操作
git上传大文件
分布式文件系统fastdfs安装以及python调用
原文地址:https://www.cnblogs.com/apiapia/p/655145.html
最新文章
设计模式之美设计原则
一文分析 Android现状及发展前景
一文详解 MySQL 安装与使用
一文了解 OpenGL ES
一文详解 OpenGL ES 3.x 渲染管线
一文详解 纹理采样与Mipmap纹理——构建山地渲染效果
一文详解 OpenGL ES 纹理颜色混合
ORA600 [kkqjpdpvpd: no join pred found.]
一看就懂的IdentityServer4认证授权设计方案 熊泽
熔断和降级的初步详解实现(NET Core控制台输出讲解Polly) 熊泽
热门文章
10分钟简单学习net core集成jwt权限认证,快速接入项目落地使用 熊泽
C#操作手册(一):命名规范 熊泽
2021年终总结:平平无奇的一年 熊泽
印象最深的一个bug:sessionStorage缓存在移动端失效 熊泽
基于echarts 24种数据可视化展示,填充数据就可用,动手能力强的还可以DIY(演示地址+下载地址) 熊泽
那些年忽略的知识:时间复杂度和空间复杂度详解 熊泽
005.系统管理监测命令
022.常见硬盘检测方式
001.AD域控简介及使用
到底谁才需要Service Mesh?
Copyright © 2011-2022 走看看