• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 769
  • Last Modified:

Rendering a tree structure

hi there

I have a tree structure and was wondering what the best way is to render it. For example, maybe using nested repeaters. Although the tree depth is limitless, i am a little lost on how to do this.

I have an item template that is like this.
<div>
<a href="#">Name of record</a>
[ChildItem]
</div>

where the [ChildItem] is the DIV structure above.

I thought of making a repeater, then making a dynamic repeater for every level downwards, recursively.

I also though that i would make the above DIV structure a usercontrol and add that along with the dynamically created repeaters.

Is this the correct method, or does anyone have example on how to do this?

I can pretty much do this however, i don't want to make something that is wrong or inefficient.

thanks
0
Valimai
Asked:
Valimai
  • 5
1 Solution
 
GreymanMSCCommented:
I'd use the asp:TreeView component.  (ASP.NET 2.0)

From where is the data being drawn?  The only problem with the TreeView is that it either uses XML datasource, or the tree needs to be programatically generated -- you cannot just use SQL.
0
 
ValimaiAuthor Commented:
i have used the tree component. My solution needs to be custom.
0
 
ValimaiAuthor Commented:
Here is a sample of what NEEDS to be rendered.
<ul>
    <li>
        <a href="#">Link 1</a>
    </li>
    <li>
        <a href="#">Link 2</a>
        <ul>
            <li>
                <a href="#">Link 2.1</a>
                <ul>
                    <li>
                        <a href="#">Link 2.1.1</a>
                        <ul>
                            <li>
                                <a href="#">Link 2.1.1.1</a>
                                <a href="#">Link 2.1.1.2</a>
                                <a href="#">Link 2.1.1.3</a>
                                <a href="#">Link 2.1.1.4</a>
                            </li>
                        </ul>
                    </li>
                </ul>
            </li>
        </ul>
    </li>
</ul>

Some items wont have children and some will have 1 to N children. The depth is limitless. And while I have produced a simple sample here, it is actually quite a complex tree that needs something like repeaters.

So I want to avoid a string contcatination or any other inefficient method to generate the tree; so was wondering if someone understood what i wanted and has a suggestion.
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
ValimaiAuthor Commented:
How i solved this was to make a usercontrol with the branch (ul) and leaves (li). I then added a placeholder where OnItemDataBound i LoadControl the same usercontrol and give it a subbranch to work with. This worked in a recursive fashion.

I could not add a reference to the same usercontrol using the register directive as it added a circular reference error, thus the LoadControl method.

<ul>
<REPEAT>
    <li>
        <a href="#">Link 1</a>
        <PLACEHOLDER></PLACEHOLDER>
    </li>
</REPEAT>
</ul>
0
 
ValimaiAuthor Commented:
There is no resolution to this problem. I would have to make my own tree control.
0
 
ValimaiAuthor Commented:
Sorry, posted the wrong comment above.
"There is no resolution to this problem. I would have to make my own tree control."
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now