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
;
}
}
查看全文
相关阅读:
20180610模拟赛T3——书本整理
20180610模拟赛T1——脱离地牢
20180606模拟赛T4——数学游戏
软工2019作业一
期末总结
<英狼>--团队作业3 王者光耀--终极版
团队作业3--王者光耀(体会)
<英狼> 团队作业2--王者光耀
王者光耀--个人任务
团队-----英狼
原文地址:https://www.cnblogs.com/Magicam/p/1233156.html
最新文章
SSD Cloud Hosting–Linode-Mysql数据库的安装与配置
FreeMarker笔记 第三章 模板
SSD Cloud Hosting
FreeMarker笔记 第二章 数值和类型
花园
又是毕业季II
[USACO13NOV]没有找零No Change
[USACO06NOV]玉米田Corn Fields
教主的花园
多边形染色
热门文章
删除子串
探寻C++最快的读取文件的方案
[ZJOI2007]棋盘制作 悬线法的运用
有线电视网 无效状态的处理
20180706模拟赛T2——染色
201800628模拟赛T2——最大土地面积
一个关于二叉树问题的证明
201800624模拟赛T2——回家路上
洛谷P4549 裴蜀定理 / Min
20180610模拟赛T4——木棍
Copyright © 2011-2022 走看看