aspnetpage分页后对内容分类

zhmjppp 2011-01-05 06:35:26
我是新手,首先我实现了对datalist通过aspnetpage分页,想在此基础上增加分类,通过DropDownList控件(值为数字),出现向对应分类,我弄了下后,类别是正确,相对应类别读取的数量是正确的,但显示的出的信息,只是在此数量里按原datalist列表里相对应类别的东西,并不是完全的。求帮助!





UI层

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();
}


web.config : <add key="pagedSPName" value="P_GetPagedProduct"/>


两个存储过程

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


...全文
59 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhmjppp 2011-01-05
  • 打赏
  • 举报
回复
没人哦...
zhmjppp 2011-01-05
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 generhappy 的回复:]
我弄了下后,类别是正确,相对应类别读取的数量是正确的,但显示的出的信息,只是在此数量里按原datalist列表里相对应类别的东西,并不是完全的

没太懂,啥意思??
[/Quote]


Cid是一个产品表里的字段,通过Cid来分类

运行后,通过DropDownList选出来的类别,如果原来分页第一页有的,就有,第一页没有,那些产品就不会显示出来
happy664618843 2011-01-05
  • 打赏
  • 举报
回复
foreach(DataListItem item in DataList1.Items){
DropDownList drop=item.FindControl() as DropDownList;
}
//在droplist onchanged事件中:
DropDownList drop=sender as DropDownList;
DataListItem dlitem=drop.parent.parent as DataListItem;
wuyq11 2011-01-05
  • 打赏
  • 举报
回复
根据类别参数查询数据
if(!IsPostBack)
{
BindData();
}
DropDownList1.SeletedValue==null?0:Convert.ToInt32(DropDownList1.Text);
if @cid>0
set @sql=@sql+' ...'
generhappy 2011-01-05
  • 打赏
  • 举报
回复
我弄了下后,类别是正确,相对应类别读取的数量是正确的,但显示的出的信息,只是在此数量里按原datalist列表里相对应类别的东西,并不是完全的

没太懂,啥意思??
zhmjppp 2011-01-05
  • 打赏
  • 举报
回复
求救a。。。

62,072

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧