zoukankan
html css js c++ java
DataList使用AspNetPager分页
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(
!
IsPostBack )
{
string
strSql;
if
( Request.QueryString.Count
==
0
)
{
strSql
=
"
select * from Product where Show=0 order by PID desc
"
;
GetAspNetPagerRecordCount( strSql );
}
else
if
( Request.QueryString[
"
PName
"
]
==
null
&
Request.QueryString[
"
KindID
"
]
!=
"
全部
"
)
{
strSql
=
"
select * from Product where KindID =
"
+
Request.QueryString[
"
KindID
"
]
+
"
and Show=0 order by PID desc
"
;
GetAspNetPagerRecordCount( strSql );
}
else
if
( Request.QueryString[
"
PName
"
]
!=
null
&
Request.QueryString[
"
KindID
"
]
!=
"
全部
"
)
{
strSql
=
"
select * from Product where PName like '%
"
+
Request.QueryString[
"
PName
"
].ToString()
+
"
%' and KindID =
"
+
Request.QueryString[
"
KindID
"
]
+
"
and Show=0 order by PID desc
"
;
GetAspNetPagerRecordCount( strSql );
}
else
if
( Request.QueryString[
"
PName
"
]
!=
null
&
Request.QueryString[
"
KindID
"
]
==
"
全部
"
)
{
strSql
=
"
select * from Product where PName like '%
"
+
Request.QueryString[
"
PName
"
].ToString()
+
"
%' and Show=0 order by PID desc
"
;
GetAspNetPagerRecordCount( strSql );
}
else
{
strSql
=
"
select * from Product where Show=0 order by PID desc
"
;
GetAspNetPagerRecordCount( strSql );
}
if
( Session[
"
UserName
"
]
==
null
||
Session[
"
UserPwd
"
]
==
null
)
{
BindDataList();
foreach
( DataListItem dl
in
DataListProduct.Items )
{
System.Web.UI.WebControls.Panel pan
=
(Panel)dl.FindControl(
"
Panel1
"
);
pan.Visible
=
true
;
System.Web.UI.WebControls.Panel pan1
=
(Panel)dl.FindControl(
"
Panel2
"
);
pan1.Visible
=
false
;
}
}
else
{
BindDataList();
foreach
( DataListItem dl
in
DataListProduct.Items )
{
System.Web.UI.WebControls.Panel pan
=
(Panel)dl.FindControl(
"
Panel1
"
);
pan.Visible
=
false
;
System.Web.UI.WebControls.Panel pan1
=
(Panel)dl.FindControl(
"
Panel2
"
);
pan1.Visible
=
true
;
}
}
}
}
private
void
GetAspNetPagerRecordCount(
string
strSql )
{
DataView dv
=
DB.GetDataView( strSql );
this
.AspNetPager1.RecordCount
=
dv.Table.Rows.Count;
this
.AspNetPager1.PageSize
=
12
;
}
protected
void
BindDataList()
{
string
strSql;
if
( Request.QueryString.Count
==
0
)
{
strSql
=
"
select * from Product where Show=0 order by PID desc
"
;
lblMsg.Text
=
"
所有商品
"
;
}
else
if
( Request.QueryString[
"
PName
"
]
==
null
&
Request.QueryString[
"
KindID
"
]
!=
"
全部
"
)
{
strSql
=
"
select * from Product where KindID =
"
+
Request.QueryString[
"
KindID
"
]
+
"
and Show=0 order by PID desc
"
;
string
sql
=
"
select KindName from Kinds where KindID =
"
+
Request.QueryString[
"
KindID
"
];
string
Msg
=
Convert.ToString( DB.ExecuteScalar( sql ) );
this
.lblMsg.Text
=
Msg;
}
else
if
( Request.QueryString[
"
PName
"
]
!=
null
&
Request.QueryString[
"
KindID
"
]
!=
"
全部
"
)
{
strSql
=
"
select * from Product where PName like '%
"
+
Request.QueryString[
"
PName
"
].ToString()
+
"
%' and KindID =
"
+
Request.QueryString[
"
KindID
"
]
+
"
and Show=0 order by PID desc
"
;
this
.lblMsg.Text
=
"
搜索结果
"
;
}
else
if
( Request.QueryString[
"
PName
"
]
!=
null
&
Request.QueryString[
"
KindID
"
]
==
"
全部
"
)
{
strSql
=
"
select * from Product where PName like '%
"
+
Request.QueryString[
"
PName
"
].ToString()
+
"
%' and Show=0 order by PID desc
"
;
this
.lblMsg.Text
=
"
搜索结果
"
;
}
else
{
strSql
=
"
select * from Product where Show=0 order by PID desc
"
;
lblMsg.Text
=
"
所有商品
"
;
}
DataListProduct.DataSource
=
DB.GetDataSetByAspNetPager( strSql, AspNetPager1 );
DataListProduct.DataBind();
}
protected
void
AspNetPager1_PageChanging(
object
src, Wuqi.Webdiyer.PageChangingEventArgs e )
{
this
.AspNetPager1.CurrentPageIndex
=
e.NewPageIndex;
if
( Session[
"
UserName
"
]
==
null
||
Session[
"
UserPwd
"
]
==
null
)
{
BindDataList();
foreach
( DataListItem dl
in
DataListProduct.Items )
{
System.Web.UI.WebControls.Panel pan
=
(Panel)dl.FindControl(
"
Panel1
"
);
pan.Visible
=
true
;
System.Web.UI.WebControls.Panel pan1
=
(Panel)dl.FindControl(
"
Panel2
"
);
pan1.Visible
=
false
;
}
}
else
{
BindDataList();
foreach
( DataListItem dl
in
DataListProduct.Items )
{
System.Web.UI.WebControls.Panel pan
=
(Panel)dl.FindControl(
"
Panel1
"
);
pan.Visible
=
false
;
System.Web.UI.WebControls.Panel pan1
=
(Panel)dl.FindControl(
"
Panel2
"
);
pan1.Visible
=
true
;
}
}
}
DB类
using
Wuqi.Webdiyer;
public
static
DataSet GetDataSetByAspNetPager(
string
strSql, AspNetPager AspNetPager )
{
try
{
OleDbConnection con
=
CreateCon();
OleDbDataAdapter sda
=
new
OleDbDataAdapter( strSql, con );
DataSet ds
=
new
DataSet();
sda.Fill( ds, AspNetPager.PageSize
*
( AspNetPager.CurrentPageIndex
-
1
), AspNetPager.PageSize,
"
table
"
);
con.Close();
con.Dispose();
return
ds;
}
catch
( Exception )
{
throw
;
}
}
查看全文
相关阅读:
贪心算法过河问题 pojo1700
大脑的合理使用
给自己的忠言
篮子水果模拟消费者生产者
线程安全高效的单例模式
Java提高篇——JVM加载class文件的原理机制
递归的研究
虚拟机分区方法
使用spark dataSet 和rdd 解决 某个用户在某个地点待了多长时间
获取数据集的好的方
原文地址:https://www.cnblogs.com/Magicam/p/1233156.html
最新文章
jQuery Ajax 全解析
SQL2008混合身份验证
SQL Server 2008中的新日期数据类型
在数据库中查询表\表字段\存储过程\存储过程变量
动态添加服务器控件
图片自动缩放 js图片缩放
银弹,构件技术
线程的基础概念
AOP IS NOT JUST A DECORATOR
Unity用法(属性注入的两种方法)
热门文章
Linq的演变
what is the difference between Association, Dependence, Aggregation and Composition
Unity用法(构造器注入的两种方法)
Unity用法(基本对象的创建的两种方法)
.net 4.5的新特性
泛型特性及内部机制
Asp.net Page LifeCycle
“jps”命令的用处?
多线程编程synchronized
forward(转发)和redirect(重定向)的区别
Copyright © 2011-2022 走看看