Results 1 to 1 of 1

Thread: Populate TreeView

  1. #1

    Thread Starter
    Addicted Member Tjoppie's Avatar
    Join Date
    Aug 2005
    Location
    South Africa
    Posts
    241

    Populate TreeView

    Hi all,

    I'm using a treeview for navigation in asp.net 2, but I don't want to use the sitemap navigation structure of the sql navigation that's out there... I just want to populate my treeview like the good ol days.

    Now, I can get it to populate parent nodes... but how do I get it to populate the child nodes? as some of my child nodes will have more child nodes... This is the code that I'm currently using (Not working), and attached is a picture of my table structure...


    VB Code:
    1. Private Sub FillTreeView()
    2.  
    3.         Try
    4.             TreeView1.Nodes.Clear()
    5.             Dim Cons As New PtechDLL.DBFunctions
    6.             Dim DBCon As String = Cons.DBConnectionstring
    7.  
    8.             Dim TreeCon As New SqlConnection(DBCon)
    9.             Dim FillTreeSQL As String = "SELECT NodeID, Title, Description, URL, Parent, UserTypeID FROM tNavigation ORDER BY ItemNumber"
    10.             Dim FillTree As New SqlCommand(FillTreeSQL, TreeCon)
    11.             TreeCon.Open()
    12.             Dim FillTreeRead As SqlDataReader = FillTree.ExecuteReader
    13.             While FillTreeRead.Read
    14.                 'If FillTreeRead("Parent") = 0 Then
    15.                 'Dim PArentNode As String = FillTreeRead("Title")
    16.                 'containerNode = TreeView1.Nodes.Add(PArentNode)
    17.                 TreeView1.Nodes.Add(New TreeNode(FillTreeRead("Title"), FillTreeRead("NodeID"), Nothing, "/test.aspx", Nothing))
    18.  
    19.  
    20.             End While
    21.  
    22.         Catch ex As System.Exception
    23.             Response.Write("There has been an error: " & vbCrLf & "This occurred in MainInterface Class Sub BindlstOnWaterRails" & vbCrLf & ex.Message & vbCrLf & "If the problem continues contact your IT department or the software vendor")
    24.         End Try
    25.  
    26.     End Sub

    In Windows forms, I can use the tag property of each node to store what the parentnode id is, and then search through it and thus add the child nodes, but treeview in asp.net doesn't have this feature... How can I structure the child nodes in this solution?

    Thanks alot all. Please see the image attached for my table structure...

    Regards,
    Attached Images Attached Images  

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width