Nested Repeater with NBearDataSource

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.