Nested Repeaters in ASP.NET

I’ve found that the simplest way to do nested repeaters without worrying about databinding events is to just set the DataSource using <%# %> syntax. For example: <asp:Repeater runat=”server” id=”Departments”> <ItemTemplate> Name: <%# Eval(“DeptName”) %> Employees: <asp:Repeater runat=”server” DataSource=”<%# Eval(“Employees”) %>”> <ItemTemplate><%# Eval(“Name”) %></ItemTemplate> <SeparatorTemplate>,</SeparatorTemplate> </asp:Repeater> </ItemTemplate> </asp:Repeater> This is presuming that your Departments class … Read more

Repeater in Repeater

In the parent repeater, attach a method to the OnItemDataBound event and in the method, find the nested repeater and data bind it. Example (.aspx): <asp:Repeater ID=”ParentRepeater” runat=”server” OnItemDataBound=”ItemBound”> <ItemTemplate> <!– Repeated data –> <asp:Repeater ID=”ChildRepeater” runat=”server”> <ItemTemplate> <!– Nested repeated data –> </ItemTemplate> </asp:Repeater> </ItemTemplate> </asp:Repeater> Example (.cs): protected void Page_Load(object sender, EventArgs e) … Read more