populating treeview menu from db(treenode not defined error)

  • Thread starter naijacoder naijacoder
  • Start date
N

naijacoder naijacoder

Hi Guys,
I have an application below that is treeview menu populated from the
database which works with asp.net webmatrix.But when i put it into code
behind in Visual Studio.Net it gives the errors

"TreeNode Not defined"
"name TreeeView1 not defined"
Can anybody tell me what 'm doing wrong?

Sub Page_load(Sender As Object, E As EventArgs)
'Connection to the DB(DB connection objects)
Dim strConn As String =
"server=(local);database=Northwind;integrated security=true;"
'Dim strConn As String =
"server=(local);database=pubs;trusted_connection=true;"

Dim objConn As New SqlConnection(strConn)

'Created a Dataset to fill in the Data
Dim objDS As New DataSet

Dim daSuppliers As New SqlDataAdapter("SELECT CompanyName,SupplierID
FROM Suppliers", objConn)
Dim daProducts As New SqlDataAdapter("SELECT ProductName, ProductID,
SupplierID FROM Products", objConn)

'Filled in the Data and close connections
'daSuppliers is the DataAdapter
daSuppliers.Fill(objDS, "dtSuppliers")
daProducts.Fill(objDS, "dtProducts")

'daSuppliers.Fill(objDS)
'daProducts.Fill(objDS)


objConn.Close()

'A relation is created here because the Dataset has more than one
Datatable (there must be a common field in both
' to define the Parent Child relationship. In this is the
SupplierID
objDS.Relations.Add("SuppToProd", _
objDS.Tables("dtSuppliers").Columns("SupplierID"), _
objDS.Tables("dtProducts").Columns("SupplierID"))


'Created TreeView datatypes
Dim nodeSupp, nodeProd As TreeNode
Dim rowSupp, rowProd As DataRow


'Loop through the datasets and populate the TreeView
For Each rowSupp In objDS.Tables("dtSuppliers").Rows

nodeSupp = New TreeNode

nodeSupp.Text = rowSupp("CompanyName")

nodeSupp.ID = rowSupp("SupplierID")

TreeView1.Nodes.Add(nodeSupp)

'Loop through SuppToProd which is a Datatable
For Each rowProd In rowSupp.GetChildRows("SuppToProd")

nodeProd = New TreeNode

nodeProd.Text = rowProd("ProductName")

'nodeProd.Text = <a href ="">" &
rowProd("ProductName") &"</a>


'<a href=""offers.asp?catID=" & rsCat("ServID") &
""">" & rsCat("ServiceName") & "</a>

nodeProd.ID = rowProd("ProductID")

nodeSupp.Nodes.Add(nodeProd)

Next

Next



'cleaned up to save server resources

objDS.Dispose()

daSuppliers.Dispose()

daProducts.Dispose()

objConn.Close()

objConn.Dispose()
End sub
 
N

naijacoder naijacoder

Hi Guys,
Now its ok just didn't add the appropriate
TreeView1 Control whch was needed in VS.Net.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top