页面 <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>View Code .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(); } }View Code ? 来源:https://www./content-4-456201.html |
|