I’m having a littl fun with ASP.Net data binding today, basically I have two nested controls, and an collection of objects with their own internal collections which I wish to bind…
So, say I’m using two repeaters like this ->
<asp:Repeater ID="Repeater1">
<ItemTemplate>
<asp:Label runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "HeaderText")%>'>
</asp:Label>
<asp:Repeater ID="Repeater2">
<asp:Label runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "DetailText")%>'>
</asp:Label>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
And my objects look like this:
public class parent
{
public string HeaderText {get;set;}
public List<child> children {get;set;}
}
public class child
{
public string DetailText {get;set;}
}
How do I bind the inner repeater? I’m guessing that I need to set & bind the datasource of ‘Repeater2’ somewhere in the aspx to be the ‘children’ property of ‘parent’?
Can someone point me in the right direction?
Thanks
Bind the nested repeater in the main repeater
ItemDataBoundevent.http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.repeater.itemdatabound.aspx
Here you can find the control (
FindControl) and bind to it.It would be something like: