views:

68

answers:

3

My data comes from a database. I have an item data table with some basic properties.

Item 
{ 
   ID, 
   Name, 
   Description, 
   ... 
} 

Then I have a many to many relationship table with:

Parent 
{ 
   ParentID, 
   ChildID 
} 

I'm iterating through each item and displaying its children; and its children's children, etc. I assume this would best be accomplished with nested repeaters, but I could be wrong.

How do I get multiple heirarchical levels using asp:repeaters? I've only ever used one nested repeater, I have no idea how to do 3+.

A: 

Personally I probably do this by creating a custom control with an Item property and some sort of either Parents or Children property. The control would display details on Item, and then use a repeater to show each element in Parents / Children, where for each item the repeater recursively uses the same control to render the item.

Kragen
A: 

I would do what @Kragen said. But if you really think that creating two components is too much you should use one repeater and two foreach loops in on data bound. Using two repeaters one inside of another is overcomplicated not to mention 3 repeaters :).

Piotr Czapla
A: 

A Parent-Child relationship, which is many-to-many? This doesn't make sense, at least calling them a parent and a child doesn't make sense. If it is really many-to-many, it's a network, if a child only has ONE parent, then it is a hierarchy.

With the former, I'm not sure visualizing them in that way is any good. How do you visualize a child with more than one parent?

With the latter, why not use a TreeView with a custom item template? It handles all the hierarchy stuff automatically. The problem with repeaters is that if you are not doing them dynamically (creating them in code), then the level of nesting is fixed and you cannot go as much as you want. Doing them dynamically would work, but would bring overhead.

I'm not very sure what exactly you are trying to accomplish. Maybe providing some more details about the end-result you need to see would be helpful.

Slavo