Hi,

I'm trying to populate my TreeView based on my Directory Structure. Actually, what I need is just the files and directories present in one folder.
I found a lot of pages, blogs and posts about this, but all the solutions require the TreeView to be inside a form.
The thing is that I'm using a MasterPage and, every time I insert a form in the page, it screw up the job done by the MasterPage.
Is there any way I can show my folder in the TreeView without put the TreeView inside a <form>?

Thanks,

Ana

Recommended Answers

All 3 Replies

TreeView is a server control, It should be enclosed within <form> tag. Also since you are using Master page, it will have a form tag so that you don't need to use a form tag in child pages where the master page is used.

Oh, Ok. Thanks for the reply.

Now I have other question. I need to add a child to a node in the TreeView. What I'm doing is

Dim newNode As TreeNode = New TreeNode(dir)
                    parentNode.Nodes.Add(newNode)

But I have this problem: Nodes is not a member of System.Web.UI.WebControls.TreeNode

In the MSDN Website, I found this example:

For Each order1 In customer2.CustomerOrders         treeView1.Nodes(customerArray.IndexOf(customer2)).Nodes.Add( _
    New TreeNode(customer2.CustomerName + "." + order1.OrderID))
      Next order1

But when I try this example on my code, I have the same problem. Is there a way to add a child node to my TreeNode?

Thanks.

I found the solution: instead of

parentNode.Nodes.Add(newNode)

I'm using

parentNode.ChildNodes.Add(newNode)

and it's working =D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.