I want to create something like this using a DataList
and Flow markup:
|-----------------------|
| Title |
|-----------------------|
| [x] Title |
| [x] Title |
| ... |
-------------------------
I have a table (modeled in Linq2Sql) Foo
that has these fields
int id;
int? parentId;
string title;
Foo Parent;
EntitySet<Foo> Children;
Now, when there is a null parent, it means it's a top level category, and if the parent has a value, it's part of the category list.
I have created a DataList
, and used a LinqDataSource
with a query that looks like this:
<asp:LinqDataSource ID="LinqDataSource1" runat="server"
ContextTypeName="MyNameSpace.FooDataContext"
Select="new (Title, Children)" TableName="Foo"
Where="ParentID = NULL">
</asp:LinqDataSource>
<asp:DataList ID="FooList" runat="server" DataSourceID="LinqDataSource1"
BorderColor="Black" BorderWidth="1px" RepeatLayout="Flow">
<ItemTemplate>
<asp:Label ID="TitleLabel" runat="server" Text='<%# Eval("Title") %>' />
<br />
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="<%# Eval("Children") %>">
<ItemTemplate>
<asp:CheckBox ID="Checks" Text="<%# Eval("Title") %>" runat="server" />
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:DataList>
This obviously doesn't work. How can I utilize the Children collection in a repeater of a DataList item?