Another solution is to simply use two repeaters, one of which is embedded in the other. You can transfer your groups with child records to the first repeater and to the ItemDataBound of the group relay, transfer the child records to the child repeater and call DataBind () there.
This is more code, but actually gives you more control over the layout without the HTML code in the code.
As you can see here, we have a parent repeater, and in the element template we can configure each group as we see fit. In ChildRepeater, we have our element template in which we can customize each element within the grouping. Very clean and all with a declarative interface.
<asp:Repeater runat="server" id="GroupRepeater"> <ItemTemplate> <asp:Literal runat="server" id="HeaderText" /> <asp:Repeater runat="server id="ChildRepeater"> <ItemTemplate> <asp:Literal runat="server" id="InfoGoesHere" /> </ItemTemplate> </asp:Repeater> </ItemTemplate> </asp:Repeater>
In the code behind, we can have something like this:
private void GroupRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e) {
After attaching each child, you can subscribe to the ItemDataBound event and attach the child to the controls as you like.
source share