I have a products table and a categories table like this (simplified)
tblHireItems: itemid(primary key, identity), itemname, categoryid, ...
categories: categoryid(primary key, identity), parentcategoryid, categoryname
There are two levels of category - top level and sub categories
I need to list top level categories as headers, followed by their contained items, followed by their sub-categories with their contained items.
Say like
(main cat1)ACCESS AND HANDLING
-item 1
-item 2
(subcat) Staging boards 600mm Wide
-item 1
-item 2
(subcat) Staging boards 450mm Wide
-item 1
-item 2
(main cat 2) LADDERS
....
I've got a repeater with a nested listview, and linking them together using LINQ . Im stumped about how to add the third one though.
Here is my front end code
Code:
<asp:Repeater ID="rptCats" runat="server">
<ItemTemplate><div class="categoryWrapper">
<h3 class="categoryTitle">
<asp:Literal ID="Literal1" runat="server" Text='<%# Eval("CatName") %>'></asp:Literal>
</h3>
<asp:ListView ID="lvHireItems" runat="server" DataSource='<%# Eval("tblHireItems") %>' ItemPlaceholderID="ph1">
<LayoutTemplate>
<p runat="server" id="ph1" ></p>
</LayoutTemplate>
<ItemTemplate>
<p><asp:Literal ID="Literal2" runat="server" text='<%# Eval("ItemName") %>'></asp:Literal></p>
</ItemTemplate>
</asp:ListView></div>
</ItemTemplate>
</asp:Repeater>
and the code behind
Code:
using (items_catsDataContext myDataContext = new items_catsDataContext())
{
var TopCats = from category in myDataContext.categories where category.categoryid >1
select new {catName = category.categoryName, category.tblHireItems};
rptCats.DataSource = TopCats;
rptCats.DataBind();
}
So I need something like
repeater (top cats)
----->listview of items where parentcategoryid = topcat
----->repeater (sub cats)
------> listview of items where parentcategoryid = subcat
Can anyone help?