<asp:Repeater runat="server" ID="rpList" OnItemDataBound="rpList_ItemDataBound"> <ItemTemplate> <div class="catItem"> <h2> <%#Eval("DataValue")%> </h2> <div class="catType"> <asp:Repeater runat="server" ID="rpListSub"> <ItemTemplate> <a href="catgory2.aspx?id=<%#Eval("Id")%>"><%#Eval("Name")%></a> </ItemTemplate> </asp:Repeater> </div> <a href="#" class="cat-more"></a> </div> </ItemTemplate> </asp:Repeater>
cs文件:
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { InitData(); } } public void InitData() { DataTable dt = SysData.GetExpertiseCategoryWeb();//web项目大类 this.rpList.DataSource = dt; this.rpList.DataBind(); } protected void rpList_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { Repeater rep = e.Item.FindControl("rpListSub") as Repeater;//找到里层的repeater对象 DataRowView rowv = (DataRowView)e.Item.DataItem;//找到分类Repeater关联的数据项 int category = Convert.ToInt32(rowv["DataKey"]);//获取填充子类的id rep.DataSource = SysData.GetExpertiseLevelDTByCategory(category); rep.DataBind(); } }
Repeater嵌套绑定Repeater,布布扣,bubuko.com
原文地址:http://blog.csdn.net/chinaboykai/article/details/25427219