zoukankan
html css js c++ java
DataGrid分页
DataGrid分页通用
void
initpage()
{
string
topsql
=
string
.Format(
@"
select count(a.ProductCode) from Production as a,MyCompanyWeb as b,Pictures as c
where a.UserSID=b.UserSID and a.ProductCode=c.ProductCode and OneFunSID={0} and State=1
"
,onefunid);
object
o
=
this
.Db.CreateStatement(topsql).GetScalar();
int
rowCount
=
0
;
if
(o
==
null
)
{
CurrentPageIndex
=
0
;
return
;
}
rowCount
=
Convert.ToInt32(o.ToString ());
if
(rowCount
%
PageSize
==
0
)
{
PageCount
=
rowCount
/
PageSize;
}
else
{
PageCount
=
rowCount
/
PageSize
+
1
;
}
lblCount.Text
=
PageCount.ToString();
if
(PageCount
>
0
)
{
CurrentPageIndex
=
1
;
GridBind();
}
else
{
DataList1.DataSource
=
new
DataTable ();
DataList1.DataBind ();
}
SetLinkLutton();
}
void
GridBind()
{
string
sqlstr
=
string
.Empty;
if
(CurrentPageIndex
==
1
)
{
sqlstr
=
String.Format (
@"
select top {0} a.ProductSID,a.ProductCode,ProductName,a.CreateTime,Quality,KeyWords,Amount,b.Company,c.ImageUrl1
from Production as a,MyCompanyWeb as b,Pictures as c
where a.UserSID=b.UserSID and a.ProductCode=c.ProductCode and OneFunSID={1} and State=1 order by a.BallotNew desc,a.CreateTime desc
"
,
this
.PageSize,onefunid);
}
else
{
int
cindex
=
(CurrentPageIndex
-
1
)
*
PageSize;
sqlstr
=
String.Format (
@"
select top {0} a.ProductSID,a.ProductCode,ProductName,a.CreateTime,Quality,KeyWords,Amount,b.Company,c.ImageUrl1
from Production as a,MyCompanyWeb as b,Pictures as c
where a.ProductSID not in (select top {1} a.ProductSID from Production as a,MyCompanyWeb as b,Pictures as c
where a.UserSID=b.UserSID and a.ProductCode=c.ProductCode and a.OneFunSID={2} and State=1 order by a.BallotNew desc,a.CreateTime desc)
and a.UserSID=b.UserSID and a.ProductCode=c.ProductCode and OneFunSID={2} and State=1 order by a.BallotNew desc,a.CreateTime desc
"
,
this
.PageSize.ToString(),cindex.ToString(),onefunid);
}
DataTable tb
=
Db.CreateStatement (sqlstr).GetDataTable ();
if
(tb
!=
null
&&
tb.Rows.Count
>
0
)
{
DataList1.DataSource
=
tb;
DataList1.DataBind ();
}
else
{
DataList1.DataSource
=
new
DataTable ();
DataList1.DataBind ();
}
SetLinkLutton();
lblCur.Text
=
CurrentPageIndex.ToString();
}
public
int
CurrentPageIndex
{
get
{
object
o
=
ViewState[
"
CurrentPageIndex
"
];
return
o
==
null
?
0
:Convert.ToInt32(o);
}
set
{
ViewState[
"
CurrentPageIndex
"
]
=
value;
}
}
public
int
PageCount
{
get
{
object
o
=
ViewState[
"
PageCount
"
];
return
o
==
null
?
0
:Convert.ToInt32(o);
}
set
{
ViewState[
"
PageCount
"
]
=
value;
}
}
public
string
sqlWhere
{
get
{
return
(
string
)ViewState[
"
SqlWhere
"
];
}
set
{
ViewState[
"
SqlWhere
"
]
=
value;
}
}
void
SetLinkLutton()
{
if
(CurrentPageIndex
==
0
)
{
lbtFirst.Enabled
=
false
;
lbtPre.Enabled
=
false
;
lbtNext.Enabled
=
false
;
lbtLast.Enabled
=
false
;
}
else
if
(CurrentPageIndex
==
1
)
{
lbtFirst.Enabled
=
false
;
lbtPre.Enabled
=
false
;
lbtNext.Enabled
=
true
;
lbtLast.Enabled
=
true
;
if
(CurrentPageIndex
==
PageCount)
{
lbtNext.Enabled
=
false
;
lbtLast.Enabled
=
false
;
}
}
else
if
(CurrentPageIndex
==
PageCount)
{
lbtFirst.Enabled
=
true
;
lbtPre.Enabled
=
true
;
lbtNext.Enabled
=
false
;
lbtLast.Enabled
=
false
;
}
else
{
lbtFirst.Enabled
=
true
;
lbtPre.Enabled
=
true
;
lbtNext.Enabled
=
true
;
lbtLast.Enabled
=
true
;
}
}
private
void
lbtLast_Click(
object
sender, System.EventArgs e)
{
this
.CurrentPageIndex
=
PageCount;
GridBind();
}
private
void
lbtNext_Click(
object
sender, System.EventArgs e)
{
if
(CurrentPageIndex
<
PageCount)
{
this
.CurrentPageIndex
=
CurrentPageIndex
+
1
;
GridBind();
}
}
private
void
lbtPre_Click(
object
sender, System.EventArgs e)
{
if
(CurrentPageIndex
>
1
)
{
this
.CurrentPageIndex
=
CurrentPageIndex
-
1
;
GridBind();
}
}
private
void
lbtFirst_Click(
object
sender, System.EventArgs e)
{
this
.CurrentPageIndex
=
1
;
GridBind();
}
查看全文
相关阅读:
Github 中使用认证签名
临时邮箱
devexpress 中的chart(图表)根据窗口大小缩放
提交特殊字符取值的处理 HttpUtility.UrlEncode
git 中 add 操作
Linux随笔
Oracle复杂多条件排序
jdk内置工具jstack查询有问题代码(具体到哪一行)
2018最新Web前端经典面试试题及答案
打包bat
原文地址:https://www.cnblogs.com/hanguoji/p/381351.html
最新文章
解决多线程访问数据冲突的问题
十条改进代码性能小建议
session和cookie的区别
时间片和抢占式
快速排序算法
归并排序算法
SQL Server中约束的介绍
SQL触发器
SQL2005数据库可疑的解决方法
SQL2005中清空操作日志的语句(SQL2008有所不同)
热门文章
SQL存储过程返回值
SQL Server 存储过程解析XML传参 参考方案
Sql 解析XML 解决方案参考
Sql 解析XML 解决方案
VS中Dev控件在工具箱里的不见的解决办法
C# 全局唯一标识符 (GUID)
DateTime 常用
C# 中常用Lambda表达式
Linux 下安装Node 安装Mongodb
Ubuntu 下安装Mysql && centos8 下安装mysql8.0
Copyright © 2011-2022 走看看