asp控件Repeater运用

双层repeater嵌套

                <asp:Repeater ID="rpt_dataRepeatgroup" runat="server" OnItemDataBound="rpt_dataRepeatgroup_ItemDataBound">
                    <HeaderTemplate>
                        
                    </HeaderTemplate>
                    <ItemTemplate>
                        <h3 class="font14 tie_bor " ><b><%# DataBinder.Eval(Container.DataItem,"Name") %></b></h3>
                        <ul class="con_list font12 clearfix" >
                            <asp:Repeater ID="rpt_dataRepeatInfo" runat="server">
                                <ItemTemplate>
                                    <li class="w1 color_blue"><%# DataBinder.Eval(Container.DataItem,"InfoName") %></li>
                                    <li class="w2 color_9"><%# Eval("Tel") %></li>
                                </ItemTemplate>
                            </asp:Repeater>
                        </ul>
                       
                    </ItemTemplate>
                    <FooterTemplate>
                    </FooterTemplate>
                </asp:Repeater>

后台代码

public void initdatas()
{
    List<Entity.CTS_Group> lstcg=new List<Entity.CTS_Group>();
    rpt_dataRepeatgroup.DataSource = lstcg;
    rpt_dataRepeatgroup.DataBind();
}
        protected void rpt_dataRepeatgroup_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Repeater rep = e.Item.FindControl("rpt_dataRepeatInfo") as Repeater;
                SHHYPortal.Entity.CTS_Group rowv = (SHHYPortal.Entity.CTS_Group)e.Item.DataItem;
                Guid groupID = rowv.ID;//用于内嵌repeater条件查询

                
               ContactInfoService cis = new ContactInfoService();
        List<Entity.CTS_Info> lstcg = cis.GetAll(a => a.GroupID == groupID).ToList();
                rep.DataSource = lstcg;
                rep.DataBind();


            }
        }            
原文地址:https://www.cnblogs.com/King-JJ/p/4940119.html