62,072
社区成员
发帖
与我相关
我的任务
分享
protected void Page_Load(object sender, EventArgs e)
{
int totalProduct = (int)SqlHelper.ExecuteScalar(CommandType.StoredProcedure, "P_GetProductNumber", new SqlParameter("@cid ", Convert.ToInt32( DropDownList1.Text)));
AspNetPager1.RecordCount = totalProduct;
bindData();
}
void bindData()
{
DataList1.DataSource = SqlHelper.ExecuteReader(CommandType.StoredProcedure, ConfigurationManager.AppSettings["pagedSPName"],
new SqlParameter("@startIndex", AspNetPager1.StartRecordIndex),
new SqlParameter("@endIndex", AspNetPager1.EndRecordIndex),
new SqlParameter("@cid ", Convert.ToInt32(DropDownList1.Text)));
DataList1.DataBind();
}
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
bindData();
}
ALTER PROCEDURE P_GetPagedProduct
(@startIndex int,
@endIndex int,
@cid int
)
as
set nocount on
declare @indextable table(id int identity(1,1),nid int) --定义一个table型的变量
set rowcount @endIndex
if @cid=0
begin
insert into @indextable(nid) select Pid from Products order by Pid desc
select Pid,Price,img,[Name]
from Products p
inner join @indextable t on
p.Pid=t.nid
where
t.id between @startIndex and @endIndex order by t.id
set nocount off
end
else
begin
insert into @indextable(nid) select Pid from Products order by Pid desc
select Pid,Price,img,[Name]
from Products p
inner join @indextable t on
p.Pid=t.nid
where cid=@cid and
t.id between @startIndex and @endIndex order by t.id
set nocount off
end
RETURN
ALTER PROCEDURE P_GetProductNumber
@cid int
AS
if @cid = 0
begin
select count(Pid) from Products where 1=1 ;
end
else
begin
select count(Pid) from Products where 1=1 and cid=@cid ;
end
RETURN