会员
周边
众包
新闻
博问
闪存
赞助商
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
Magicam_落叶Ф孤星
人随落叶叶随风,何处相见何处逢。独自孤星逐日夜,奈何枫叶夜随风!
博客园
首页
新随笔
联系
管理
订阅
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
;
}
}
posted @
2008-07-01 14:05
Magicam
阅读(
1845
) 评论(
0
)
编辑
收藏
举报
刷新页面
返回顶部
公告