[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 427
  • Last Modified:

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!
0
bertino12
Asked:
bertino12
  • 5
  • 5
1 Solution
 
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
 
bertino12Author Commented:
Yes asp .net, so how do you add items dynamically?
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

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