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
;
}
}
查看全文
相关阅读:
Git clone The requested URL returned error: 403 错误
创建DOTA2本地数据库(一)
如何打开VPK文件?里面究竟有什么?
DOTA 2 API(个人资料)
新的博客,新的开始!
你应该在开始API开发之前知道的事(下)(翻译)
你应该在开始API开发之前知道的事(上)(翻译)
DOTA 2 Match History WebAPI(翻译)
C#中UnixTime和DateTime的转换(转载)
搜查令中期总结
原文地址:https://www.cnblogs.com/Magicam/p/1233156.html
最新文章
第二周作业
第五周课程总结和第三周实验报告
第四周学习总结与实验报告二
第九周课程总结&实验报告七
第六周&Java实验报告四
第十周课程总结
第二周学习总结
第七周课程总结&实验报告五
第三周学习报告与总结
第十一周作业
热门文章
web.config配置文件中的属性add,key,value含义
Winform中导入导出Excel
.net 磁盘映射/清空
Git问题解决:warning: Pulling without specifying how to reconcile divergent branches is discouraged.
linux安装pcntl拓展
Linux查看与关闭端口
Linux下生成git秘钥
JS创建空对象,对象属性的添加与删除
安装swoole拓展报错configure: error: C preprocessor "/lib/cpp" fails sanity check
报错:Fatal error: Call to undefined function pcntl_signal()
Copyright © 2011-2022 走看看