Repeater嵌套绑定
Posted chenlihong-886
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Repeater嵌套绑定相关的知识,希望对你有一定的参考价值。
页面
<div class="list1"> <asp:Repeater ID="rptlist" runat="server" OnItemDataBound="rptlist_ItemDataBound"> <ItemTemplate> <div class="titlebox"> <div class="title"> <h1><%# Eval("title") %></h1> </div> <ul> <asp:Repeater ID="rptItem" runat="server"> <ItemTemplate> <li><a href=‘/roomShow.aspx?cid=<%#Eval("roomid") %>‘><%# Eval("title") %></a></li> </ItemTemplate> <FooterTemplate> <div class="clear"></div> </FooterTemplate> </asp:Repeater> </ul> </div> </ItemTemplate> </asp:Repeater> </div>
.cs文件
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { DataSet ds = new BLL.rooms().GetList("parentid=0"); DataTable dt = ds.Tables[0]; this.rptlist.DataSource = ds.Tables[0]; this.rptlist.DataBind(); } } protected void rptlist_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { Repeater rep = e.Item.FindControl("rptItem") as Repeater;//找到里层的repeater对象 DataRowView rowv = (DataRowView)e.Item.DataItem; String pid = rowv["roomid"].ToString(); DataSet ds = new BLL.rooms().GetList(" parentid=" + pid); rep.DataSource = ds.Tables[0]; rep.DataBind(); } }
以上是关于Repeater嵌套绑定的主要内容,如果未能解决你的问题,请参考以下文章