APS.NET中Repeater嵌套使用

发布于 2017-11-08  200 次阅读


这两天刚发现,项目里老师这样写的,以前都不知道.

比如这种情况

上面为分类名 下面为此分类下的海报。

   

 <!--注意有个事件 item绑定时-->
 <asp:Repeater ID="rptType" runat="server" OnItemDataBound="rptType_ItemDataBound">
 <ItemTemplate>
 <asp:HiddenField ID="hfProductTypeID" Value='<%# Eval("ItemID") %>' runat="server" />
 <div class="info">
 <%#Eval("ProductTypeName")%>
 <a href="javascript:;">
 <img style="width: 55px; height: 18px;"
 src="/Biz/Mobile/css/admin/img/download.png" alt=""></a>
 </div>
 <div class="pos">
 <asp:Repeater ID="rptTypePoster" runat="server">
 <ItemTemplate>
 <div class="po">
 <img src="<%#Eval("PosterPath")%>" alt=""><span><%#Eval("PosterTitle").ToString().Ext_GetLongestStr(5,false) %></span>
 </div>
 </ItemTemplate>
 </asp:Repeater>
 </div>
 <div style="clear: both;"></div>
 </ItemTemplate>
 </asp:Repeater>

// 后台代码
 protected void rptType_ItemDataBound(object sender, RepeaterItemEventArgs e)
 {
 if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
 {
 HiddenField hfProductTypeID = e.Item.FindControl("hfProductTypeID") as HiddenField;
 Repeater rptTypePoster = e.Item.FindControl("rptTypePoster") as Repeater;

 string sql = string.Format(" select * from Mobile_Poster where ItemID in (select PosterID from Biz_Product_Poster where UserID={0} and ProductID={1})", uid, hfProductTypeID.Value);
 //给repeator绑定数据
 rptTypePoster.Ext_BindRepeater(sql);
 }
 }

LoneKing