Net-informations.com
SiteMap  | About    

Treeview Control

The TreeView control contains a hierarchy of TreeViewItem controls. You can use the TreeView control to display information from a wide variety of data sources such as an XML file, site-map file, string, or from a database. It provides a way to display information in a hierarchical structure by using collapsible nodes . The top level in a tree view are root nodes that can be expanded or collapsed if the nodes have child nodes

treeview-control

The user can expand the TreeNode by clicking the plus sign (+) button, if one is displayed next to the TreeNode, or you can expand the TreeNode by calling the TreeNode.Expand method

The fullpath method of treeview control provides the path from root node to the selected node.

vb.net

  Label1.Text = TreeView1.SelectedNode.ValuePath

C#

  treeView1.SelectedNode.FullPath.ToString ();

The following ASP.NET program shows how to load data from an XML file to a Treeview control. The XML file you can download from

http://asp.net-informations.com/webcontrols/websites.xml

Default.aspx

  

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
	<title>Untitled Page</title>
</head>
<body>
	<form id="form1" runat="server">
	<div>
		<asp:TreeView ID="TreeView1" runat="server"
			onselectednodechanged="TreeView1_SelectedNodeChanged">
		</asp:TreeView>
	</div>
	   <asp:XmlDataSource
		id="websites"
		DataFile="http://asp.net-informations.com/webcontrols/websites.xml"
		Runat="server" />
	<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
	</form>
</body>
</html>


Click the following links to see full source code

C# Source Code
VB.NET Source Code
default.aspx.cs
default.aspx.vb






net-informations.com (C) 2017    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.