473,386 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Populating four levels of tree view from the database

34
Hi all,
I am trying to populate tree view from the database. Till two levels i can populate it fine but when it reaches third level it doesn't expand. Below is the code, it has been taken from the reference of micrososft

Sub PopulateNode(ByVal sender As Object, ByVal e As TreeNodeEventArgs)

' Call the appropriate method to populate a node at a particular level.
If e.Node.ChildNodes.Count = 0 Then

Select Case e.Node.Depth

Case 0
' Populate the first-level nodes.
PopulateCategories(e.Node)

Case 1
' Populate the second-level nodes.
PopulateProducts(e.Node)

Case 2
' Populate the third-level nodes.
PopulateResources(e.Node)

Case Else
'do mothing

End Select
Else
e.Node.Parent.Text = "xx"
End If

End Sub

Sub PopulateCategories(ByVal node As TreeNode)

' Query for the product categories. These are the values
' for the second-level nodes.
Dim ResultSet As DataSet = RunQuery("SELECT Block4.BlockCode, sessiontype.type, sessiontype.BlockID,sessiontype.SessionID FROM Block4 INNER JOIN sessiontype ON Block4.BlockID = sessiontype.BlockID Where Block4.BlockCode='xx'")

' Create the second-level nodes.
If ResultSet.Tables.Count > 0 Then

' Iterate through and create a new node for each row in the query results.
' Notice that the query results are stored in the table of the DataSet.
Dim row As DataRow

For Each row In ResultSet.Tables(0).Rows

' Create the new node. Notice that the CategoryId is stored in the Value property
' of the node. This will make querying for items in a specific category easier when
' the third-level nodes are created.
Dim newNode As TreeNode = New TreeNode()
'newNode.Text = "Seminars"
newNode.Text = row("type").ToString()
newNode.Value = row("SessionID").ToString()

' Set the PopulateOnDemand property to true so that the child nodes can be
' dynamically populated.
newNode.PopulateOnDemand = True

' Set additional properties for the node.
newNode.SelectAction = TreeNodeSelectAction.Expand

' Add the new node to the ChildNodes collection of the parent node.
node.ChildNodes.Add(newNode)

Next

End If

End Sub
Sub PopulateProducts(ByVal node As TreeNode)

' Query for the product categories. These are the values
' for the second-level nodes.
Dim ResultSet As DataSet = RunQuery("SELECT semsymp4.stitle,semsymp4.ID,sessiontype.type FROM semsymp4 INNER JOIN sessiontype ON semsymp4.SessionID = sessiontype.SessionID where semsymp4.SessionID=" & node.Value)

' Create the second-level nodes.
If ResultSet.Tables.Count > 0 Then

' Iterate through and create a new node for each row in the query results.
' Notice that the query results are stored in the table of the DataSet.
Dim row As DataRow

For Each row In ResultSet.Tables(0).Rows

' Create the new node. Notice that the CategoryId is stored in the Value property
' of the node. This will make querying for items in a specific category easier when
' the third-level nodes are created.
Dim newNode As TreeNode = New TreeNode()
'newNode.Text = "Seminars"
newNode.Text = row("stitle").ToString()
newNode.Value = row("ID").ToString()

' Set the PopulateOnDemand property to true so that the child nodes can be
' dynamically populated.
newNode.PopulateOnDemand = True

' Set additional properties for the node.
newNode.SelectAction = TreeNodeSelectAction.Expand


' Add the new node to the ChildNodes collection of the parent node.
node.ChildNodes.Add(newNode)


Next

End If

End Sub


Sub PopulateResources(ByVal node As TreeNode)

' Query for the products of the current category. These are the values
' for the third-level nodes.

Dim ResultSet As DataSet = RunQuery("SELECT Resources.ResourceID, Resources.ResourceTitle,Resources.ResourceURL,Reso urces.ID, semsymp4.ID AS Expr1, semsymp4.stitle FROM Resources INNER JOIN semsymp4 ON Resources.ID = semsymp4.ID where Resources.ID=" & node.Value)

' Create the third-level nodes.
If ResultSet.Tables.Count > 0 Then

' Iterate through and create a new node for each row in the query results.
' Notice that the query results are stored in the table of the DataSet.
Dim row As DataRow

For Each row In ResultSet.Tables(0).Rows

' Create the new node.
Dim NewNode As TreeNode = New TreeNode(row("ResourceTitle").ToString())
'NewNode.NavigateUrl = row("ResourceURL").ToString

' Set the PopulateOnDemand property to false, because these are leaf nodes and
' do not need to be populated.
NewNode.PopulateOnDemand = False

' Set additional properties for the node.
'NewNode.SelectAction = TreeNodeSelectAction.None
'
' Add the new node to the ChildNodes collection of the parent node.

node.ChildNodes.Add(NewNode)

Next

End If

End Sub

Function RunQuery(ByVal QueryString As String) As DataSet

' Declare the connection string. This example uses Microsoft SQL Server
' and connects to the Northwind sample database.
Dim ConnectionString As String = "xxx"

Dim DBConnection As SqlConnection = New SqlConnection(ConnectionString)
Dim DBAdapter As SqlDataAdapter
Dim ResultsDataSet As DataSet = New DataSet
Response.Write(QueryString)
' Try

' Run the query and create a DataSet.
DBAdapter = New SqlDataAdapter(QueryString, DBConnection)
DBAdapter.Fill(ResultsDataSet)

' Close the database connection.
DBConnection.Close()

'Catch ex As Exception

' Close the database connection if it is still open.
If DBConnection.State = ConnectionState.Open Then

DBConnection.Close()

End If

'Message.Text = "Unable to connect to the database."

' End Try

Return ResultsDataSet

End Function


I don't understand what the problem is ,
Please, if you could help me. It's urgent.
Jun 14 '07 #1
0 1700

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Steve Johnson | last post by:
Been banging my head on this for two days now. Hope someone can help! My test program below is in the form of a single JSP, with a Node class build in. (All the coded needed to run is below.) ...
5
by: Travis Pupkin | last post by:
Hey, I've done a number of product catalogs/galleries with one or two category levels (Category > Subcategory). The straightforward way to do this, of course, is to use database fields for...
3
by: imani_technology_spam | last post by:
We need to present hierarchical data on a web page, the same way the tree view shows files in Windows Explorer. Here's the catch: that tree view needs to be bound to a SQL Server database. How...
0
by: serge calderara | last post by:
Dear all, I have an VB windows application that colect information form a remote database and then populate the tree view with part of the reords. As database data can be huge , I have used the...
0
by: Tree menu using XML | last post by:
I have one XML file that has nodes and sub node and each and every node has the attribute call visible if its value is true then diplay this node else don't display thid node, but this condition i...
5
by: Shane | last post by:
I wonder if someone has any ideas about the following. I am currently producing some reports for a manufacturing company who work with metal. A finished part can contain multiple sub-parts to...
2
by: James L | last post by:
I have finally developed some code that allows you to re populate a tree view and re select the last node that was clicked. However, you have to hard code it for the number of levels the tree view...
3
by: babu17 | last post by:
hi , I have a database table with 3 columns table1: eid ename parentid 0 root 0 1 child1 0 2 child2 0
7
by: sosamv | last post by:
Hi all!, I'm creating a app with PHP and MySQL, the system administrator is capable of creating profiles, on each profile we create, we add a custom access menu (a javascript tree view menu), theres...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.