populating treeview menu from db(treenode not defined error)

Discussion in 'ASP .Net' started by naijacoder naijacoder, Sep 14, 2004.

  1. 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


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    naijacoder naijacoder, Sep 14, 2004
    #1
    1. Advertising

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


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    naijacoder naijacoder, Sep 15, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. tanya foster
    Replies:
    3
    Views:
    3,786
    tanya foster
    May 18, 2006
  2. Oodini
    Replies:
    1
    Views:
    1,843
    Keith Thompson
    Sep 27, 2005
  3. abargaddon
    Replies:
    0
    Views:
    1,101
    abargaddon
    Jan 17, 2008
  4. Patrick.O.Ige

    TreeNodeCollection & TreeNode not defined

    Patrick.O.Ige, Oct 20, 2004, in forum: ASP .Net Web Controls
    Replies:
    15
    Views:
    408
  5. Blaenzo

    Casting error with extended treenode in treeview

    Blaenzo, Jun 19, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    148
    Blaenzo
    Jun 19, 2006
Loading...

Share This Page