Populate Treeview child nodes from a database

I build a treeviews parent and 1st child nodes from a sitemap. so it looks like this:

- Cars
    - Ford
    - Nissan
 
Now I hit the database and generate a datatable, dt("Ford Models"). How do I bind the datatable to the "ford" child node so it looks like this?
- Cars
     - Ford
           - Taurus
           - Mustang
           - Fusion
Thanks!
bertino12Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

bertino12Author Commented:
Right now, I am just trying it like this, but when the page is finished loading it doesnt display the node as populated.
    Private Sub Page1_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Page1.Unload
        Dim dt As DataTable = popRootNodes()
        Dim parentNode As TreeNode = Nothing
        Dim currNode As TreeNode = Nothing
        Dim newNode As TreeNode = Nothing
 
        parentNode = Me.TreeView1.Nodes.Item(0)
        currNode = parentNode.ChildNodes.Item(0)
 
        newNode = New TreeNode("Taurus", "Taurus")
        currNode.ChildNodes.Add(newNode)
 
        newNode = New TreeNode("Mustang", "Mustang")
        currNode.ChildNodes.Add(newNode)
 
        newNode = New TreeNode("Fusion", "Fusion")
        currNode.ChildNodes.Add(newNode)
 
        currNode.Expanded = True
    End Sub

Open in new window

0
Randy Wilson.Net DeveloperCommented:
Is this ASP.Net?  Web TreeView has no Item collection...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bertino12Author Commented:
Yes asp .net, so how do you add items dynamically?
0
Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

Randy Wilson.Net DeveloperCommented:
parentNode = Me.TreeView1.Nodes.Add(someTreeNodehere)
0
Randy Wilson.Net DeveloperCommented:
If you are looking for a more complete answer, post more complete code.  BTW, why are you doing this in the Page Unload Event?
0
bertino12Author Commented:
Ok for the web treeview use PopulateOnDemand
0
Randy Wilson.Net DeveloperCommented:
There is no PopulateOnDemand property/method for the Web TreeView.  Would not make sense in the PostBack (stateless) environment of the web.
0
Randy Wilson.Net DeveloperCommented:
My bad, did not pay attention to the question..
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.