Solved

Populate Treeview child nodes from a database

Posted on 2009-07-15
10
393 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
  • 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:
wrwilson 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
 
LVL 7

Expert Comment

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

Expert Comment

by:wrwilson
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Closing Comment

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

Expert Comment

by:wrwilson
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
 

Author Comment

by:bertino12
ID: 24862218
0
 

Author Comment

by:bertino12
ID: 24862253
0
 
LVL 7

Expert Comment

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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Reduced with of radio button in the page 2 38
Duplicate a row 2 33
Problem to go to Web page 2 52
dynamic menu in asp.net c# 11 30
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now