[Root Node Text]>> [Node1Text] >> [Node2 Text] >> [Node3 Text] >>
<%@ Page Language="C#" Theme="Default" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
foreach (TreeNode node in ExampleDemo.Nodes)
{
SetNode(node);
}
}
void SetNode(TreeNode node)
{
if (node.Depth != 0)
{
node.Text = node.Parent.Text + ">>" + node.Text;
}
if (node.ChildNodes.Count > 0)
{
foreach (TreeNode childnode in node.ChildNodes)
{
SetNode(childnode);
}
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>TreeView works like SiteMapPath Demo</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TreeView ID="ExampleDemo" runat="server">
<Nodes>
<asp:TreeNode Text="NewsMedia">
<asp:TreeNode Text="Favorites">
<asp:TreeNode Text="News">
<asp:TreeNode Text="MSN" NavigateUrl="http://www.msn.com" />
<asp:TreeNode Text="MSNBC News" NavigateUrl="http://www.msnbc.msn.com" />
</asp:TreeNode>
<asp:TreeNode Text="Technology">
<asp:TreeNode Text="Microsoft" NavigateUrl="http://www.microsoft.com" />
<asp:TreeNode Text="ASP.NET" NavigateUrl="hhttp://24x7aspnet.blogspot.com/" />
<asp:TreeNode Text="ASPDotNet" NavigateUrl="http://24x7aspnet.blogspot.com/" />
<asp:TreeNode Text="MSDN" NavigateUrl="http://msdn.microsoft.com" />
</asp:TreeNode>
<asp:TreeNode Text="Movie">
<asp:TreeNode Text="MSN Movie" NavigateUrl="http://Movie.msn.com" />
<asp:TreeNode Text="MSN Autos" NavigateUrl="http://autos.msn.com" />
</asp:TreeNode>
</asp:TreeNode>
<asp:TreeNode Text="City Visit">
<asp:TreeNode Text="MapPoint" NavigateUrl="http://www.mappoint.com" />
<asp:TreeNode Text="MSN City Guides" NavigateUrl="http://local.msn.com" />
</asp:TreeNode>
<asp:TreeNode Text="Music Links">
<asp:TreeNode Text="MSN Music" NavigateUrl="http://music.msn.com" />
</asp:TreeNode>
</asp:TreeNode>
</Nodes>
</asp:TreeView>
</div>
</form>
</body>
</html>
<%@ Page Language="C#" Theme="Default" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
foreach (TreeNode node in ExampleDemo.Nodes)
{
SetNode(node);
}
}
void SetNode(TreeNode node)
{
if (node.Depth != 0)
{
node.Text = node.Parent.Text + ">>" + node.Text;
}
if (node.ChildNodes.Count > 0)
{
foreach (TreeNode childnode in node.ChildNodes)
{
SetNode(childnode);
}
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>TreeView works like SiteMapPath Demo</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TreeView ID="ExampleDemo" runat="server">
<Nodes>
<asp:TreeNode Text="NewsMedia">
<asp:TreeNode Text="Favorites">
<asp:TreeNode Text="News">
<asp:TreeNode Text="MSN" NavigateUrl="http://www.msn.com" />
<asp:TreeNode Text="MSNBC News" NavigateUrl="http://www.msnbc.msn.com" />
</asp:TreeNode>
<asp:TreeNode Text="Technology">
<asp:TreeNode Text="Microsoft" NavigateUrl="http://www.microsoft.com" />
<asp:TreeNode Text="ASP.NET" NavigateUrl="hhttp://24x7aspnet.blogspot.com/" />
<asp:TreeNode Text="ASPDotNet" NavigateUrl="http://24x7aspnet.blogspot.com/" />
<asp:TreeNode Text="MSDN" NavigateUrl="http://msdn.microsoft.com" />
</asp:TreeNode>
<asp:TreeNode Text="Movie">
<asp:TreeNode Text="MSN Movie" NavigateUrl="http://Movie.msn.com" />
<asp:TreeNode Text="MSN Autos" NavigateUrl="http://autos.msn.com" />
</asp:TreeNode>
</asp:TreeNode>
<asp:TreeNode Text="City Visit">
<asp:TreeNode Text="MapPoint" NavigateUrl="http://www.mappoint.com" />
<asp:TreeNode Text="MSN City Guides" NavigateUrl="http://local.msn.com" />
</asp:TreeNode>
<asp:TreeNode Text="Music Links">
<asp:TreeNode Text="MSN Music" NavigateUrl="http://music.msn.com" />
</asp:TreeNode>
</asp:TreeNode>
</Nodes>
</asp:TreeView>
</div>
</form>
</body>
</html>