zoukankan
html css js c++ java
asp.net Repeater中嵌套使用Repeater
在一般的网站中浏览类别的用户控件通常都位于大多数 ASP.NET 页的左边,它使用户能够按类别快速的查找产品。最近遇到一个客户,因为在他网站上展示的产品并不多,所以要求在原有类别浏览的基础上将产品也加进去。一来更方便,二来加长了左部导航栏的长度使页面更协调。原有的分类导航栏是由Repeater实现的,现在需要在每一个分类下加入该类的商品信息,于是我想到了在原有Repeater中嵌套Repeater。实现界面如下:
前台页面部分:
<
asp:Repeater id
=
"
rptCategories
"
runat
=
"
server
"
>
<
HeaderTemplate
>
<
table width
=
"
100%
"
border
=
"
0
"
cellspacing
=
"
0
"
cellpadding
=
"
0
"
>
</
HeaderTemplate
>
<
ItemTemplate
>
<!--
分类名称
-->
<
tr
><
th
><%
# DataBinder.Eval(Container.DataItem,
"
TypeName
"
)
%></
th
></
tr
>
<!--
分类下的产品
-->
<
asp:Repeater id
=
"
rptProduct
"
runat
=
"
server
"
>
<
ItemTemplate
>
<
tr
><
td
><
a href
=
'
ProductInfo.aspx?Id=<%# DataBinder.Eval(Container.DataItem, "ID") %>
'
><%
# DataBinder.Eval(Container.DataItem,
"
ProductName
"
)
%></
a
></
td
></
tr
>
</
ItemTemplate
>
</
asp:Repeater
>
</
ItemTemplate
>
<
FooterTemplate
>
</
table
>
</
FooterTemplate
>
</
asp:Repeater
>
后台代码部分(部分代码):
//
在绑定分类品名时,绑定分类下的产品
private
void
rptCategories_ItemDataBound(
object
sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
{
BLL.Products products
=
new
BLL.Products();
if
(e.Item.ItemType
==
ListItemType.Item
||
e.Item.ItemType
==
ListItemType.AlternatingItem)
{
Repeater rptProduct
=
(Repeater) e.Item.FindControl(
"
rptProduct
"
);
//
找到分类Repeater关联的数据项
DataRowView rowv
=
(DataRowView)e.Item.DataItem;
//
提取分类ID
int
CategorieId
=
Convert.ToInt32(rowv[
"
ID
"
]);
//
根据分类ID查询该分类下的产品,并绑定产品Repeater
rptProduct.DataSource
=
products.GetProductsByCategorieId(CategorieId);
rptProduct.DataBind();
}
}
查看全文
相关阅读:
poj 1035 字符串匹配
拓扑排序的小总结
POJ1018
POJ1328详细题解
POJ1159题解报告
POJ1088 (滑雪)
树状树组区间修改,单点修改模板
spfa模板
树状树组离散化求逆序对模板
POJ3723(最小生成树,负权)
原文地址:https://www.cnblogs.com/wucf2004/p/770111.html
最新文章
luogu P6371 [COCI2006-2007#6] V 数位dp
luogu P5058 [ZJOI2004]嗅探器 割点
Codeforces Round #466 (Div. 2) F. Machine Learning 莫队+分块 带修莫队的模板题
luogu P3758 [TJOI2017]可乐 分层图dp
luogu P2709 小B的询问 分块+莫队
luogu P3901 数列找不同 莫队+分块
【算法】最短路
【最短路】POJ 3268 Silver Cow Party
【最短路】POJ 1502 MPI Maelstrom
【最短路】POJ-2387 Til the Cows Come Home
热门文章
【题解】[kuangbin带你飞] 专题四 最短路
【算法】最短路
【算法】最短路
【算法】最小生成树-Kruskal算法
【暴力】B
【模拟】A
POJ2349
dijkstra算法的简单应用与板子
Prim算法的简单入门与板子
矩阵快速幂HDU2065
Copyright © 2011-2022 走看看