TreeView control in ASP.NET using VB.NET

In this article we will learn how to use TreeView control in ASP.NET.
  • 3752

In this article we will learn how to use TreeView control in ASP.NET.

TreeView control

The TreeView control is suitable for displaying XML data, but can be used for any data that can be represented in a hierarchy. The tree view provides an object oriented hierarchical or parent/child relationship view of data and meta-data. The most common example of a tree view is Windows Explorer's directory structure where disk drives contain folders, folders contain sub-folders and folders contain files.

Node property:

Initial collection of the nodes for the tree. The TreeNode class provides a property named node. This property is a great place to store meta-data you may need to access either on the client or on the server.

tv 1.gif

Figure 1.

Now click on the node property from the property window.


Figure 2.

For example: Drag treeview control on the form and set node property of the form. The form looks like this.


Figure 3.

Now click on the source button and add the following code directly.

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm2.aspx.vb" Inherits="WebApplication22.WebForm2" %>

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">

<head runat="server">




<form id="form1" runat="server">


    <asp:TreeView ID="TreeView1" runat="server">


    <asp:TreeNode Text="My Computer">

    <asp:TreeNode Text="Favorites">

    <asp:TreeNode Text="News"> 

        <asp:TreeNode Text="MSN" NavigateUrl=""/>

        <asp:TreeNode Text="MSNBC News" NavigateUrl=""/>


    <asp:TreeNode Text="Technology"> 

        <asp:TreeNode Text="Microsoft" NavigateUrl=""/>

        <asp:TreeNode Text="ASP.NET" NavigateUrl=""/>

        <asp:TreeNode Text="GotDotNet" NavigateUrl=""/>

        <asp:TreeNode Text="MSDN" NavigateUrl=""/>


    <asp:TreeNode Text="Shopping"> 

        <asp:TreeNode Text="MSN Shopping" NavigateUrl=""/>

        <asp:TreeNode Text="MSN Autos" NavigateUrl=""/>



    <asp:TreeNode Text="City Links">

    <asp:TreeNode Text="MapPoint" NavigateUrl=""/>

    <asp:TreeNode Text="MSN City Guides" NavigateUrl=""/>


    <asp:TreeNode Text="Music Links">

    <asp:TreeNode Text="MSN Music" NavigateUrl=""/>









Now save and run the application.


Figure 4.

Suppose we click on the MSN then following(""/>) link will be open.


More Articles

© 2020 DotNetHeaven. All rights reserved.