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
;
}
}
查看全文
相关阅读:
MySQL协议分析(2)
MySQL协议分析(1)
《汇编语言》知识重点总结
opencv学习(1.2)
CentOS 6下OpenCV的安装与配置
python2与python3之间的主要区别
python-PEP8编码规范
解决windows 10无法打开.hlp帮助文件的问题
将windows server 2016改造为像windows 10一样适合个人使用的系统
系统分析师成长之路
原文地址:https://www.cnblogs.com/Magicam/p/1233156.html
最新文章
NHibernate的几种查询方式
【C#】Color颜色对照表
crystal report水晶报表在浏览器提示bobj未定义的错误,或者程序改为Framework4.0后,打印报表不显示
H3C F100-C60 端口映射配置
VS 调试运行4.0程序报错,webconfig中不识别Framework4.0标记
sqlserver复制订阅(发布订阅)读库改为写库用(订阅库改为主库用)
同服务器两个数据库联合查询
手动编写一个简单的loadrunner脚本
码农的工匠精神
Python之多线程:线程互斥与线程同步
热门文章
Python之多线程:Threading模块
快速排序
Python实现队列
Python实现求矩阵路径最小和,使用动态规划
Python之Excel编程
Python之面向对象:类的内置方法
Python之面向对象:闭包和装饰器
脚本其实很简单-爱心打印脚本(2)
脚本其实很简单-windows配置核查程序(1)
脚本其实很简单-爱心打印脚本(1)
Copyright © 2011-2022 走看看