Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7675921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:04:47+00:00 2026-05-31T17:04:47+00:00

I have a requirement to create a multi level treeview in ASP.Net (with VB)

  • 0

I have a requirement to create a multi level treeview in ASP.Net (with VB) but I am completely stuck on how to start this. Currently my treeview is a fixed 2 level approach but now I need to rewrite this to be more dynamic and support extra levels being added into our database tables.

So this treeview needs to support as many levels as needed without having to rewrite any code each time we want to add new level, Ideally we will just insert the data at the database level.

I think I have the database part designed correctly, I created 2 tables Menu and MenuItems

Menu has 2 columns ItemID and ChildID

MenuItems has 2 columns ItemID and Description

Doing this query:

SELECT 
    menu.Item_ID, 
    menu.Child_ID , 
    parent.ID,
    parent.Description,
    child.ID,
    child.Description 
FROM 
    tblSupportTicketMenu menu
JOIN 
    tblSupportTicketMenuItems parent
ON
    parent.ID = menu.Item_ID
JOIN
    tblSupportTicketMenuItems child
ON
    child.ID = menu.Child_ID 

Will return this data:

Item_ID     Child_ID    ID          Description                                                                                          ID          Description
----------- ----------- ----------- ---------------------------------------------------------------------------------------------------- ----------- ----------------------------------------------------------------------------------------------------
32          33          32          Level 1                                                                                              33          Level 2
33          34          33          Level 2                                                                                              34          Level 3
35          36          35          Item 2 Level 1                                                                                       36          Item 2 Level 2
36          37          36          Item 2 Level 2                                                                                       37          Item 2 Level 3

From here I am unsure where to go, I read that the asp Treeview can take XML as its datasource and this seems to be a good idea, but how could I select the data into a format which would support multiple levels etc?

If anyone knows how to do this or could link me to a guide I would be very appreciative, also if doing this as XML is a bad idea I am open to other suggestions, I’m still learning ASP.Net so I would like to do this properly.

To be thorough this is the code I am currently replacing which generates the treeview for me.

   Dim ds As New DataTable

      Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("Blueprint").ToString())

      Dim cmd As New SqlCommand
      cmd.CommandType = CommandType.StoredProcedure
      cmd.CommandText = "spGetMenuItemsForTickets"

      cmd.Connection = conn

      Using da As New SqlDataAdapter(cmd)
         conn.Open()
         da.Fill(ds)
         conn.Close()
      End Using

      Dim ParentIds As List(Of Integer) = New List(Of Integer)

      For Each row As DataRow In ds.Rows

         If ParentIds.Contains(row("ParentID")) Then
            '' Do Nothing 
         Else
            ParentIds.Add(row("ParentID"))
         End If
      Next

      For Each Parent As Integer In ParentIds
         Dim parentNode As New System.Web.UI.WebControls.TreeNode

         For Each child In ds.Rows
            If (child("ParentID") = Parent) Then

               Dim childNode As New System.Web.UI.WebControls.TreeNode

               parentNode.Text = child("ParentDescription")
               parentNode.Value = child("ParentID")
               parentNode.Expanded = False

               childNode.Text = child("ChildDescription")
               childNode.Value = child("ChildID")


               parentNode.SelectAction = TreeNodeSelectAction.None
               parentNode.ChildNodes.Add(childNode)
            End If
         Next
         trvItem.Nodes.Add(parentNode)
      Next

      trvItem.Nodes(0).Text += String.Empty
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T17:04:48+00:00Added an answer on May 31, 2026 at 5:04 pm

    The database structure you have created seems ok however rename itemid to parentid and childid to itemid would be more understandable to me ( I like to see parentid for the current item)

    You can go step by step by reading following link , they tried to make it simple to understand. I hope this will help.

    http://aspalliance.com/732_Display_Hierarchical_Data_with_TreeView_in_ASPNET_20

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have requirement to create an asp.net wizard control which will be re usable
I am completely new to java, but I have urgent requirement to create a
Normally I create web application projects and use code-behind, but I have a requirement
I have a requirement to create a sysDesk log file. In this requirement I
I have a requirement to create jar files with Maven, but they need to
I have a requirement to create XML that looks like this: <record id=100000000000000000 type=Message>
I have a requirement to create a simple database in Access to collect some
I have a requirement to create a windows form control which has to detect
I have a requirement to create a simple windows forms application that allows an
I have a requirement to create two different maps in C++. The Key is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.