Reference resources:
1. nested use of Repeater in Repeater
2. How To Display Hierarchical Data by Using Nested Repeater Controls and Visual C #. NET
3. nested Repeater
4. Add the ItemDataBound event to the nested repeater.
5. [CN. Text Development Notes] nested Repeater Problems
6. nested repeater (vs2005) in repeater)
7. Two Repeater nesting schemes
8. Scott Mitchell's ASP. NET 2.0 data Tutorial: nesting of Data Controls
Most group:
Solution 1: Each binding generates NBearDataSource and sets NBearDataSource. Filter () in ItemDataBound ().
The Code is as follows: Design Code
<% @ Register TagPrefix = "nb" Namespace = "NBear. Web. Data" Assembly = "NBear. Web. Data" %>
<Nb: NBearDataSource ID = "nbdsLinkCategorys" runat = "server" ConnectionStringName = "Access"
TypeName = "Entities. LinkCategory"> </nb: NBearDataSource>
<Asp: Repeater ID = "rptLinkCategories" performanceid = "nbdsLinkCategorys" runat = "server" OnItemDataBound = "rptLinkCategories_ItemDataBound">
<ItemTemplate>
<Div class = "box">
<H3> <% # Eval ("Name") %> <Ul> <nb: NBearDataSource ID = "nbdsLinks" runat = "server" ConnectionStringName = "Access"
TypeName = "Entities. Link"/>
<Asp: Repeater ID = "rptLinks" performanceid = "nbdsLinks" runat = "server">
<ItemTemplate>
<Li>
<A href = '<% # Eval ("Src") %>'
Runat = "server" title = '<% # "click to view-" + Eval ("Title") %>'> <% # Eval ("Title ") %> </a>
</Li>
</ItemTemplate>
</Asp: Repeater>
</Ul>
</Div>
</ItemTemplate>
</Asp: Repeater>
Source code
Protected void rptLinkCategories_ItemDataBound (object sender, RepeaterItemEventArgs e)
{
If (e. Item. ItemType = ListItemType. AlternatingItem | e. Item. ItemType = ListItemType. Item)
{
LinkCategory category = (LinkCategory) e. Item. DataItem;
NBearDataSource nbds = (NBearDataSource) e. Item. FindControl ("nbdsLinks ");
Nbds. Filter (Link. _. CategoryID = category. ID );
}
}
Disadvantage: if there are N Linkcategory entries, this method will access the database N + 1-return all Linkcategory records at a time, and return the Links under a specific Linkcategory records at a time.
Solution 2: You only need to access the data twice, get all LinkCategories at a time, and get all Links at a time.