Solved

Populate Treeview child nodes from a database

Posted on 2009-07-15
10
405 Views
Last Modified: 2012-05-07
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
Comment
Question by:bertino12
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 

Author Comment

by:bertino12
ID: 24860101
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
 
LVL 7

Accepted Solution

by:
Randy Wilson earned 500 total points
ID: 24861252
Is this ASP.Net?  Web TreeView has no Item collection...
0
 

Author Comment

by:bertino12
ID: 24861633
Yes asp .net, so how do you add items dynamically?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Expert Comment

by:Randy Wilson
ID: 24861935
parentNode = Me.TreeView1.Nodes.Add(someTreeNodehere)
0
 
LVL 7

Expert Comment

by:Randy Wilson
ID: 24861956
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
 

Author Closing Comment

by:bertino12
ID: 31603874
Ok for the web treeview use PopulateOnDemand
0
 
LVL 7

Expert Comment

by:Randy Wilson
ID: 24862182
There is no PopulateOnDemand property/method for the Web TreeView.  Would not make sense in the PostBack (stateless) environment of the web.
0
 
LVL 7

Expert Comment

by:Randy Wilson
ID: 24862274
My bad, did not pay attention to the question..
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question