GridView的另外一种分页方式,可提高加载速度
发布日期:2021-05-14 04:36:50 浏览次数:8 分类:博客文章

本文共 5069 字,大约阅读时间需要 16 分钟。

���������������������������������������������GridView������������������������������������������������������������������������������������������������������������������������Oracle���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������CodeProject���������������������������������������������������������������������������������������������������������������������������������������������������������������

������������������������

������������������������������

1���������DataReader

2������������������������������������������DataReader

3������������������������������

4������������������������DataTable������������

5���������DataReader

6���������DataTable������������

������������������������������������������������������������������������DataReaderToDataTable���������������������������������

internal
static
DataTable DataReaderToDataTable(
string
sQuery,
int
iStart,
int
iEnd) { DataTable schematable
=
null
; DataTable dt
=
null
; SqlCommand cmdsql; SqlDataReader dr
=
null
; SqlConnection conn
=
null
;
long
icount
=
0
;
try
{
//
������������������������������DataReader
conn
=
new
SqlConnection(ConnString); conn.Open(); cmdsql
=
new
SqlCommand(sQuery, conn); dr
=
cmdsql.ExecuteReader(CommandBehavior.CloseConnection); schematable
=
dr.GetSchemaTable(); dt
=
new
DataTable();
//
Get the Schema of Tables Columns and its types, and load the same into DataTable.
for
(
int
i
=
0
; i
<=
schematable.Rows.Count
-
1
; i
++
) { DataRow dRow
=
schematable.Rows[i]; DataColumn column
=
new
DataColumn(); column.DataType
=
System.Type.GetType(dRow[
"
DataType
"
].ToString()); column.AllowDBNull
=
(dRow[
"
AllowDBNull
"
].ToString()
==
"
True
"
?
true
:
false
); column.ColumnName
=
dRow[
"
ColumnName
"
].ToString(); column.Caption
=
dRow[
"
ColumnName
"
].ToString(); dt.Columns.Add(column);
//
More DataTable property can be added as required.
}
if
(iStart
==
0
) iStart
=
1
;
if
(iEnd
==
0
) iEnd
=
1
; icount
=
1
;
//
Loop the Reader which is executed till the Start and Variable,
//
Fetch and add the rows one by one to Data Table Till the End Count is reached.
//
Exit the loop and Return Datable.
while
(dr.Read()) {
if
(icount
>=
iStart
&&
icount
<=
iEnd) { DataRow dRow
=
dt.NewRow();
for
(
int
i
=
0
; i
<=
dr.FieldCount
-
1
; i
++
) { dRow[i]
=
dr.GetValue(i); } dt.Rows.Add(dRow); }
else
if
(icount
>
iEnd) {
break
; } icount
=
icount
+
1
; } }
catch
(SystemException ex) {
throw
ex; }
finally
{ conn.Close(); conn.Dispose(); schematable.Dispose(); dr.Close(); dr.Dispose(); }
return
dt; }

������������������GridView������������������

private
void
BindData(
int
pageIndex) {
int
startRow;
int
endRow; startRow
=
(pageIndex
*
grdEmployee.PageSize)
+
1
; endRow
=
startRow
+
grdEmployee.PageSize
-
1
;
������������������ grdEmployee.DataSource
=
CustomPaging.Class.Common.DataReaderToDataTable(SelectQuery,startRow,endRow); grdEmployee.DataBind();
}

 ���������������������������������������������������������

上一篇:jQuery 1.4.2中的.bind(),.live()&.delegate()方法解析
下一篇:Table表格的隔行变色,高亮选择当前行效果

发表评论

最新留言

能坚持,总会有不一样的收获!
[***.219.124.196]2025年04月14日 13时38分33秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章

2021-04-23 2021-05-12
Linux编程基础之创建两个子进程而不创建孙子进程 2021-05-12
另一个树的子树 2021-05-12
hadoop 分布式文件系统的计算和高可用 2021-05-12
2021-05-08 2021-05-12
【Linux】VMware Workstation 不可恢复错误: (vcpu-0) 2021-05-12
VS中 fatal error LNK1123: 转换到 COFF 期间失败 的解决方法 2021-05-12
关于Img标签在固定宽高的容器内部以图片比例缩放存在 2021-05-12
python3---读写文件、POST表单请求、HTML处理、列表分割遍历,进行暴力破解用户名与密码 2021-05-12
Android Studio基础项目-布局XML设置的实战-全屏显示登录界面,去除按钮深颜色 2021-05-12
python --- 监控客户端是否存活 2021-05-12
pyhton---异常处理的终极语法、网页访问基本读取、网页访问异常处理 2021-05-12
Centos 7.3 计算本目录下的以特定名字文件夹个数 2021-05-12
linux下编程出现 对'sem_wait'未定义的引用解决方案 2021-05-12
工具研究:(三)Nginx配置错误的路由时均统一跳转到登录界面 2021-05-12
前端框架(react+umi+dva+ant design pro )攻克: 二、react 父子组件通信(二) 2021-05-12
ant design pro v5去掉右边content区域的水印 2021-05-12
get/set方法是外界访问对象私有属性的唯一通道,方法内部可对数据进行检测和过滤(代码演示) 2021-05-12
web_求和(练习) 2021-05-12
JavaScript——使用iterator遍历迭代map,set集合元素 2021-05-12