Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

treenode error in treeview menu program

Status
Not open for further replies.

afybim

Technical User
Nov 13, 2002
16
TR
Hi,
I want to do a treeview menu which is driven by sql server database..
I found this code in the internet but i am giving an error "type treenode is not defined" and "type treenodecollection is not defined"
I have imported all necessary libraries..
Could you help me please..

Codes:
----------------------------------------

<asp:TreeView
ID="TreeView1"
ExpandDepth="0"
PopulateNodesFromClient="true"
ShowLines="true"
ShowExpandCollapse="true"
runat="server" />
------------------------------------------------------------


Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
PopulateRootLevel()
End If
End Sub

Private Sub PopulateRootLevel()
Dim objConn As New SqlConnection(_
"server=JOTEKE\SQLExpress;Trusted_Connection=true;DATABASE=TreeViewSampleDB")
Dim objCommand As New SqlCommand("select id,title,(select count(*) FROM SampleCategories " _
& "WHERE parentid=sc.id) childnodecount FROM SampleCategories sc where parentID IS NULL", _
objConn)

Dim da As New SqlDataAdapter(objCommand)
Dim dt As New DataTable()
da.Fill(dt)

PopulateNodes(dt, TreeView1.Nodes)
End Sub


Private Sub PopulateNodes(ByVal dt As DataTable, _
ByVal nodes As TreeNodeCollection)
For Each dr As DataRow In dt.Rows
Dim tn As New TreeNode()
tn.Text = dr("title").ToString()
tn.Value = dr("id").ToString()
nodes.Add(tn)

'If node has child nodes, then enable on-demand populating
tn.PopulateOnDemand = (CInt(dr("childnodecount")) > 0)
Next
End Sub







Private Sub PopulateSubLevel(ByVal parentid As Integer, _
ByVal parentNode As TreeNode)
Dim objConn As New SqlConnection(_
"server=JOTEKE\SQLExpress;Trusted_Connection=true;DATABASE=TreeViewSampleDB")
Dim objCommand As New SqlCommand("select id,title,(select count(*) FROM SampleCategories " _
& "WHERE parentid=sc.id) childnodecount FROM SampleCategories sc where parentID=@parentID", _
objConn)
objCommand.Parameters.Add("@parentID", SqlDbType.Int).Value = parentid

Dim da As New SqlDataAdapter(objCommand)
Dim dt As New DataTable()
da.Fill(dt)
PopulateNodes(dt, parentNode.ChildNodes)
End Sub


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top