前台代码:
<!--顶部菜单栏 联盟品牌中心 js特效绑定开始--> <ul class="sublist"> <asp:Repeater ID="Repeaterp_fl" runat="server" onitemdatabound="Repeaterp_fl_ItemDataBound"> <ItemTemplate> <li> <h3 class="mcate-item-hd"> <span><%#Eval("br_typename")%></span> </h3> <p class="mcate-item-bd"> <asp:Repeater ID="Repeaterp_zl" runat="server"> <ItemTemplate> <a href="#"><%#Eval("br_smalltypename") %></a> </ItemTemplate> </asp:Repeater> </p> </li> </ItemTemplate> </asp:Repeater> </ul> <!--顶部菜单栏 联盟品牌中心 js特效绑定结束-->
后台代码:
/// <summary> /// 绑定顶部父类的菜单 一级Repeater /// </summary> private void getFcd() { this.Repeaterp_fl.DataSource = brandtbll.GetList(12, "", "br_tid desc"); this.Repeaterp_fl.DataBind(); } /// <summary> /// 绑定二级Repeater子菜单 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Repeaterp_fl_ItemDataBound(object sender, RepeaterItemEventArgs e) { // BLL.Products products = new BLL.Products(); if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { Repeater repzl = (Repeater)e.Item.FindControl("Repeaterp_zl"); //找到分类Repeater关联的数据项 DataRowView rowv = (DataRowView)e.Item.DataItem; //提取分类ID int CategorieId = Convert.ToInt32(rowv["br_tid"]); //根据分类ID查询该分类下的产品,并绑定产品Repeater repzl.DataSource = brandsmallbll.GetList("br_tid="+CategorieId); repzl.DataBind(); } }
显示效果: