ASP.Net/Components/Tree — различия между версиями

Материал из .Net Framework эксперт
Перейти к: навигация, поиск
м (1 версия)
 
м (1 версия)
 
(нет различий)

Текущая версия на 11:51, 26 мая 2010

Add tree node (C#)

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<script runat="server">
    protected void btnSubscribe_Click(object sender, EventArgs e)
    {
        foreach (TreeNode node in TreeView1.CheckedNodes)
            bltSubscribed.Items.Add(node.Text);
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>TreeView CheckBoxes</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    Select the Newsgroups which you 
    would like to join: 
    
    <br />
    
    <asp:TreeView
        id="TreeView1"
        ShowCheckBoxes="Leaf"
        Runat="server">
        <Nodes>
        <asp:TreeNode
            Text="Programming">
            <asp:TreeNode Text="ASP.NET" />
            <asp:TreeNode Text="JAVA" />
            <asp:TreeNode Text="Cold Fusion" />
        </asp:TreeNode>
        <asp:TreeNode
            Text="Sports">
            <asp:TreeNode Text="Baseball" />
            <asp:TreeNode Text="Hockey" />
            <asp:TreeNode Text="Football" />
        </asp:TreeNode>        
        </Nodes>
    </asp:TreeView>    
    
    <br />
    
    <asp:Button
        id="btnSubscribe"
        Text="Subscribe"
        OnClick="btnSubscribe_Click"
        Runat="server" />
    
    <hr />
    
    You selected:
    
    <asp:BulletedList
        id="bltSubscribed"
        EnableViewState="false"
        Runat="server" />
    
    </div>
    </form>
</body>
</html>



IE control treeview with link node (C#)

<%@ Register TagPrefix="iewc" Namespace="Microsoft.Web.UI.WebControls" Assembly="Microsoft.Web.UI.WebControls" %>
<%@ Page language="c#" src="TreeViewTest.aspx.cs" AutoEventWireup="false" Inherits="TreeViewTest" %>
<HTML>
  <body MS_POSITIONING="GridLayout">
    <form id="Form1" method="post" runat="server">
      <asp:Label id="Label1" style="Z-INDEX: 102; LEFT: 20px; POSITION: absolute; TOP: 264px" runat="server" Height="80px" Width="316px">Note: None of the links under My Site will work, because these pages do not exist.</asp:Label>
      <iewc:TreeView id="TreeView1" style="Z-INDEX: 103; LEFT: 16px; POSITION: absolute; TOP: 12px" runat="server" Height="252px" Width="356px" AutoPostBack="True"></iewc:TreeView>
    </form>
  </body>
</HTML>

<%--
using System;
using System.Collections;
using System.ruponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Microsoft.Web.UI.WebControls;
  public class TreeViewTest : System.Web.UI.Page
  {
    protected System.Web.UI.WebControls.Label Label1;
    protected Microsoft.Web.UI.WebControls.TreeView TreeView1;
  
    private void Page_Load(object sender, System.EventArgs e)
    {
      if (!this.IsPostBack)
      {
        Microsoft.Web.UI.WebControls.TreeNode rootNode;
        rootNode = AddNode("default.aspx", "My Site", "Folder", 
          TreeView1.Nodes);
        AddNode("info.aspx", "Contact Page", "Page", rootNode.Nodes) ;
        rootNode.Expanded = true;
        rootNode = AddNode("links.aspx", "Links", "Folder", 
          TreeView1.Nodes);
        AddNode("http://www.nfex.ru", "nfex.ru", "Page",  
          rootNode.Nodes);
        AddNode("http://www.google.ru", "Google", "Page", 
          rootNode.Nodes);
        rootNode.Expanded = true;
      }
    }
      private Microsoft.Web.UI.WebControls.TreeNode AddNode(string id, string text, 
        string type, Microsoft.Web.UI.WebControls.TreeNodeCollection nodeCollection)
      {
        Microsoft.Web.UI.WebControls.TreeNode node = new Microsoft.Web.UI.WebControls.TreeNode();
        node.Text = text;
        node.Type = type;
        node.ID = id;
        nodeCollection.Add(node);
        return node;
      }
    #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
      //
      // CODEGEN: This call is required by the ASP.NET Web Form Designer.
      //
      InitializeComponent();
      base.OnInit(e);
    }
    
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {    
      this.TreeView1.SelectedIndexChange += new Microsoft.Web.UI.WebControls.SelectEventHandler(this.TreeView1_SelectedIndexChange);
      this.Load += new System.EventHandler(this.Page_Load);
    }
    #endregion
    private void TreeView1_SelectedIndexChange(object sender, Microsoft.Web.UI.WebControls.TreeViewSelectEventArgs e)
    {
      Microsoft.Web.UI.WebControls.TreeNode selectedNode = TreeView1.GetNodeFromIndex(e.NewNode);
      Response.Redirect(selectedNode.ID);
    }
  }

--%>



IE control tree with link node and frame control (C#)

<%@ Page language="c#" src="TreeFrame.aspx.cs" AutoEventWireup="false" Inherits="TreeFrame" %>
<%@ Register TagPrefix="iewc" Namespace="Microsoft.Web.UI.WebControls" Assembly="Microsoft.Web.UI.WebControls" %>
<HTML>
  <body>
    <form id="Form1" method="post" runat="server">
      <iewc:TreeView id="TreeView1" style="Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 8px" runat="server"
        Width="228px" Height="363px" AutoPostBack="True" BorderStyle="None" BorderWidth="2px" Indent="15">
        <iewc:TreeNodeType ImageUrl="folder.gif" Type="Folder"></iewc:TreeNodeType>
        <iewc:TreeNodeType ImageUrl="page.gif" Type="Page"></iewc:TreeNodeType>
      </iewc:TreeView>
      <asp:Label id="Label1" style="Z-INDEX: 102; LEFT: 20px; POSITION: absolute; TOP: 264px" runat="server"
        Height="80px" Width="102px">Note: None of the links under My Site will work, because these pages do not exist.</asp:Label>
    </form>
  </body>
</HTML>

<%--
using System;
using System.Collections;
using System.ruponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Microsoft.Web.UI.WebControls;
  public class TreeFrame : System.Web.UI.Page
  {
    protected System.Web.UI.WebControls.Label Label1;
    protected Microsoft.Web.UI.WebControls.TreeView TreeView1;
  
    private void Page_Load(object sender, System.EventArgs e)
    {
      if (!this.IsPostBack)
      {
        Microsoft.Web.UI.WebControls.TreeNode rootNode;
        rootNode = AddNode("default.aspx", "My Site", "Folder", 
          TreeView1.Nodes);
        AddNode("info.aspx", "Contact Page", "Page", rootNode.Nodes) ;
        rootNode.Expanded = true;
        rootNode = AddNode("links.aspx", "Links", "Folder", 
          TreeView1.Nodes);
        AddNode("http://www.google.ru", "Google", "Page", 
          rootNode.Nodes);
        AddNode("http://www.nfex.ru", "nfex.ru", "Page", rootNode.Nodes);
        AddNode("http://www.google.ru", "Google", "Page", 
          rootNode.Nodes);
        rootNode.Expanded = true;
      }
    }
    private Microsoft.Web.UI.WebControls.TreeNode AddNode(string id, string text, 
      string type, Microsoft.Web.UI.WebControls.TreeNodeCollection nodeCollection)
    {
      Microsoft.Web.UI.WebControls.TreeNode node = new Microsoft.Web.UI.WebControls.TreeNode();
      node.Text = text;
      node.Type = type;
      node.ID = id;
      nodeCollection.Add(node);
      return node;
    }
    #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
      //
      // CODEGEN: This call is required by the ASP.NET Web Form Designer.
      //
      InitializeComponent();
      base.OnInit(e);
    }
    
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {    
      this.TreeView1.SelectedIndexChange += new Microsoft.Web.UI.WebControls.SelectEventHandler(this.TreeView1_SelectedIndexChange);
      this.Load += new System.EventHandler(this.Page_Load);
    }
    #endregion
    private void TreeView1_SelectedIndexChange(object sender, Microsoft.Web.UI.WebControls.TreeViewSelectEventArgs e)
    {
      Microsoft.Web.UI.WebControls.TreeNode selectedNode = TreeView1.GetNodeFromIndex(e.NewNode);
      string url = selectedNode.ID;
       
      // Use JavaScript to trigger the redirect in the other window.
      string frameScript = "<script language="javascript">" +
          "window.parent.frames(1).location="" + url + "";" + "</script>";
      Page.RegisterStartupScript("FrameScript", frameScript);
    }
  }

--%>



On Tree Node Populate Event (C#)

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<script runat="server">
        void TreeView1_TreeNodePopulate(object s, TreeNodeEventArgs e)
        {
            for (int i=0;i<5;i++)
            {
                TreeNode newNode = new TreeNode();
                newNode.Text = String.Format("{0}.{1}", e.Node.Text, i);
                newNode.PopulateOnDemand = true;
                e.Node.ChildNodes.Add(newNode);
            }
        }
    
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>TreeView Populate On Demand</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <%=DateTime.Now.ToString("T") %>        
    
    <hr />
    <asp:TreeView 
        ID="TreeView1" 
        ExpandDepth="0"
        OnTreeNodePopulate="TreeView1_TreeNodePopulate" 
        Runat="server">
        <Nodes>
        <asp:TreeNode
            PopulateOnDemand="true"
            Text="Node 0" />
        </Nodes>
    </asp:TreeView>
    
    </div>
    </form>
</body>
</html>



On tree node selection changed event (C#)

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<script runat="server">
    protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
    {
        lblMessage.Text = TreeView1.SelectedValue;
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <style type="text/css">
        html
        {
            background-color:silver;
        }
        .content
        {
            float:left;
            width:350px;
            height:500px;
            padding:20px;
            margin:10px;
            background-color:white;
        }
    </style>
    <title>TreeView Value</title>
</head>
<body>
    <form id="form1" runat="server">
    
    <div class="content">
    <asp:TreeView
        id="TreeView1"
        OnSelectedNodeChanged="TreeView1_SelectedNodeChanged"
        Runat="server" >
        <Nodes>
        <asp:TreeNode
            Text="Home"
            Value="Home">
            <asp:TreeNode
                Text="Products">
                <asp:TreeNode
                    Text="First Product"
                    Value="FirstProduct" />
                <asp:TreeNode
                    Text="Second Product"
                    Value="SecondProduct" />
            </asp:TreeNode>
            <asp:TreeNode
                Text="Services">
                <asp:TreeNode
                    Text="First Service"
                    Value="FirstService" />
                <asp:TreeNode
                    Text="Second Service"
                    Value="SecondService" />
            </asp:TreeNode>    
        </asp:TreeNode>    
        </Nodes>
    </asp:TreeView>    
    </div>
    
    <div class="content">
    You selected:
    <asp:Label
        id="lblMessage"
        EnableViewState="false"
        Runat="server" />
    </div>
    
    </form>
</body>
</html>



Setting Styles in a TreeView Control (VB.net)

<%@ Page Language=VB Debug=true %>
<%@ Import Namespace="Microsoft.Web.UI.WebControls" %>
<%@ Register TagPrefix="IEControls" 
    Namespace="Microsoft.Web.UI.WebControls" 
    Assembly ="Microsoft.Web.UI.WebControls"
%>
<script runat=server>
Sub Page_Load(ByVal Sender as Object, ByVal E as EventArgs)
End Sub
Sub SubmitBtn_Click(Sender As Object, E As EventArgs)
End Sub
</SCRIPT>
<HTML>
<HEAD>
<TITLE>Setting Styles in a TreeView Control</TITLE>
</HEAD>
<BODY LEFTMARGIN="40">
<form runat="server">
<IEControls:treeview
    id="tvBasic"
    defaultstyle="color:darkblue;background-color:pink;
        font-family:Arial"
    selectedstyle="color:red;background-color:purple;
        font-family:Arial"
    hoverstyle="color:green;background-color:yellow;font-family:
        Comic Sans MS"
    runat="server">
    <IEControls:treenode Text="Clothing">
        <IEControls:treenode Text="Men"s"/>
        <IEControls:treenode Text="Women"s"/>
        <IEControls:treenode Text="Children"s">
            <IEControls:treenode Text="Socks"/>
            <IEControls:treenode Text="Shirts"/>
            <IEControls:treenode Text="Pants"/>
        </IEControls:treenode>
    </IEControls:treenode>
    <IEControls:treenode Text="Electronics">
        <IEControls:treenode Text="TV/VCR"/>
        <IEControls:treenode Text="Audio"/>
        <IEControls:treenode Text="Car"/>
        <IEControls:treenode Text="Computer"/>
    </IEControls:treenode>
</IEControls:treeview>
</form>
</BODY>
</HTML>



Static WebControls treeview (VB.net)

<%@ Page Language=VB Debug=true %>
<%@ Import Namespace="Microsoft.Web.UI.WebControls" %>
<%@ Register TagPrefix="IEControls" 
    Namespace="Microsoft.Web.UI.WebControls" 
    Assembly ="Microsoft.Web.UI.WebControls"
%>
<HTML>
<HEAD>
<TITLE>TreeView 1 Control Sample Page</TITLE>
</HEAD>
<BODY>
<form runat="server">
<Font Face="Tahoma">
<IEControls:treeview
    id="MyTree1"
    AutoSelect="False"
    ShowPlus="True"
    ExpandLevel=2
    runat="server">
    <IEControls:treenode Text="A">
        <IEControls:treenode Text="A1"/>
        <IEControls:treenode Text="A2"/>
        <IEControls:treenode Text="A3">
            <IEControls:treenode Text="A31"/>
            <IEControls:treenode Text="A32"/>
            <IEControls:treenode Text="A33"/>
        </IEControls:treenode>
    </IEControls:treenode>
    <IEControls:treenode Text="B">
        <IEControls:treenode Text="B1"/>
        <IEControls:treenode Text="B2"/>
        <IEControls:treenode Text="B3"/>
        <IEControls:treenode Text="B4"/>
    </IEControls:treenode>
</IEControls:treeview>
</Font>
</Form>
</BODY>
</HTML>



TreeNode Collapses action (VB.net)

<%@ Page Language=VB Debug=true %>
<%@ Import Namespace="Microsoft.Web.UI.WebControls" %>
<%@ Register TagPrefix="IEControls" 
    Namespace="Microsoft.Web.UI.WebControls" 
    Assembly ="Microsoft.Web.UI.WebControls"
%>
<script runat=server>
Sub Node_Collapse(ByVal Sender as Object, _
    ByVal E as TreeViewClickEventArgs)
    lblMessage.Text = "You collapse node " _
        & E.Node.ToString() & "."
End Sub
</SCRIPT>
<HTML>
<HEAD>
<TITLE>Writing Code that Fires When a TreeNode Collapses</TITLE>
</HEAD>
<BODY LEFTMARGIN="40">
<form runat="server">
<IEControls:treeview
    id="tvBasic"
    oncollapse="Node_Collapse"
    autopostback="True"
    runat="server">
    <IEControls:treenode Text="Clothing">
        <IEControls:treenode Text="Men"s"/>
        <IEControls:treenode Text="Women"s"/>
        <IEControls:treenode Text="Children"s">
            <IEControls:treenode Text="Socks"/>
            <IEControls:treenode Text="Shirts"/>
            <IEControls:treenode Text="Pants"/>
        </IEControls:treenode>
    </IEControls:treenode>
    <IEControls:treenode Text="Electronics">
        <IEControls:treenode Text="TV/VCR"/>
        <IEControls:treenode Text="Audio"/>
        <IEControls:treenode Text="Car"/>
        <IEControls:treenode Text="Computer"/>
    </IEControls:treenode>
</IEControls:treeview>
<BR>
<asp:Label
    id="lblMessage"
    runat="server"
    FOnt-Bold="True"
/>
</form>
</BODY>
</HTML>



TreeNode Expand action (VB.net)

<%@ Page Language=VB Debug=true %>
<%@ Import Namespace="Microsoft.Web.UI.WebControls" %>
<%@ Register TagPrefix="IEControls" 
    Namespace="Microsoft.Web.UI.WebControls" 
    Assembly ="Microsoft.Web.UI.WebControls"
%>
<script runat=server>
Sub Node_Expand(ByVal Sender as Object, _
    ByVal E as TreeViewClickEventArgs)
    lblMessage.Text = "You expanded node " _
        & E.Node.ToString() & "."
End Sub
</SCRIPT>
<HTML>
<HEAD>
<TITLE>Writing Code that Fires When a TreeNode Expands</TITLE>
</HEAD>
<BODY LEFTMARGIN="40">
<form runat="server">
<IEControls:treeview
    id="tvBasic"
    onexpand="Node_Expand"
    autopostback="True"
    runat="server">
    <IEControls:treenode Text="Clothing">
        <IEControls:treenode Text="Men"s"/>
        <IEControls:treenode Text="Women"s"/>
        <IEControls:treenode Text="Children"s">
            <IEControls:treenode Text="Socks"/>
            <IEControls:treenode Text="Shirts"/>
            <IEControls:treenode Text="Pants"/>
        </IEControls:treenode>
    </IEControls:treenode>
    <IEControls:treenode Text="Electronics">
        <IEControls:treenode Text="TV/VCR"/>
        <IEControls:treenode Text="Audio"/>
        <IEControls:treenode Text="Car"/>
        <IEControls:treenode Text="Computer"/>
    </IEControls:treenode>
</IEControls:treeview>
<BR>
<asp:Label
    id="lblMessage"
    runat="server"
    FOnt-Bold="True"
/>
</form>
</BODY>
</HTML>



Tree Node selected event in a TreeView (VB.net)

<%@ Page Language=VB Debug=true %>
<%@ Import Namespace="Microsoft.Web.UI.WebControls" %>
<%@ Register TagPrefix="IEControls" 
    Namespace="Microsoft.Web.UI.WebControls" 
    Assembly ="Microsoft.Web.UI.WebControls"
%>
<script runat=server>
Sub Node_Selected(ByVal Sender as Object, _
    ByVal E as TreeViewSelectEventArgs)
    lblMessage.Text = "You selected node " & E.NewNode.ToString() _
        & " and moved from node " & E.OldNode.ToString() & "."
End Sub
</SCRIPT>
<HTML>
<HEAD>
<TITLE>Writing Code that Fires When a TreeNode Control in a TreeView Control is Selected</TITLE>
</HEAD>
<BODY LEFTMARGIN="40">
<form runat="server">
<IEControls:treeview
    id="tvBasic"
    onselectedindexchange="Node_Selected"
    autopostback="True"
    runat="server">
    <IEControls:treenode Text="Clothing">
        <IEControls:treenode Text="Men"s"/>
        <IEControls:treenode Text="Women"s"/>
        <IEControls:treenode Text="Children"s">
            <IEControls:treenode Text="Socks"/>
            <IEControls:treenode Text="Shirts"/>
            <IEControls:treenode Text="Pants"/>
        </IEControls:treenode>
    </IEControls:treenode>
    <IEControls:treenode Text="Electronics">
        <IEControls:treenode Text="TV/VCR"/>
        <IEControls:treenode Text="Audio"/>
        <IEControls:treenode Text="Car"/>
        <IEControls:treenode Text="Computer"/>
    </IEControls:treenode>
</IEControls:treeview>
<BR>
<asp:Label
    id="lblMessage"
    runat="server"
    FOnt-Bold="True"
/>
</form>
</BODY>
</HTML>



Tree node with hyper link (C#)

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>TreeView Declare</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    <asp:TreeView
        id="TreeView1"
        Runat="server">
        <Nodes>
        <asp:TreeNode
            Text="Home"
            NavigateUrl="~/Default.aspx">
            <asp:TreeNode
                Text="Products">
                <asp:TreeNode
                    Text="First Product"
                    NavigateUrl="http://www.nfex.ru" />
                <asp:TreeNode
                    Text="Second Product"
                    NavigateUrl="http://www.nfex.ru" />
            </asp:TreeNode>
            <asp:TreeNode
                Text="Services">
                <asp:TreeNode
                    Text="First Service"
                    NavigateUrl="http://www.nfex.ru" />
                <asp:TreeNode
                    Text="Second Service"
                    NavigateUrl="http://www.nfex.ru" />
            </asp:TreeNode>    
        </asp:TreeNode>    
        </Nodes>
    </asp:TreeView>    
    
    
    </div>
    </form>
</body>
</html>



Treeview and checkbox treenode (VB.net)

<%@ Page Language=VB Debug=true %>
<%@ Import Namespace="Microsoft.Web.UI.WebControls" %>
<%@ Register TagPrefix="IEControls" 
    Namespace="Microsoft.Web.UI.WebControls" 
    Assembly ="Microsoft.Web.UI.WebControls"
%>
<HTML>
<HEAD>
<TITLE>Working with TreeNode Controls in a TreeView Control</TITLE>
</HEAD>
<BODY LEFTMARGIN="40">
<form runat="server">
<IEControls:treeview
    id="tvBasic"
    autoselect="True"
    runat="server">
    <IEControls:treenode text="Electronics">
        <IEControls:treenode 
            text="A"
            checkbox="True"/>
        <IEControls:treenode 
            text="B"
            checkbox="True"/>
        <IEControls:treenode
            Checked 
            text="C"
            checkbox="True"/>
        <IEControls:treenode 
            text="D"
            checkbox="True"/>
    </IEControls:treenode>
</IEControls:treeview>
</form>
</BODY>
</HTML>



Treeview image: XP file explore style (C#)

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>TreeView ImageSet</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    <asp:TreeView
        id="TreeView1"
        ImageSet="XPFileExplorer"
        ShowLines="true"
        Runat="server">
        <Nodes>
        <asp:TreeNode
            Text="Home">
            <asp:TreeNode Text="Products">
                <asp:TreeNode Text="First Product" />
                <asp:TreeNode Text="Second Product" />
            </asp:TreeNode>
            <asp:TreeNode Text="Services">
                <asp:TreeNode Text="First Service" />
                <asp:TreeNode Text="Second Service" />
            </asp:TreeNode>    
        </asp:TreeNode>    
        </Nodes>
    </asp:TreeView>    
    
    
    </div>
    </form>
</body>
</html>



Tree view node style (C#)

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <style type="text/css">
        .nodeLevel1
        {
            font:40px Arial,Sans-Serif;
        }
        .nodeLevel2
        {
            font:20px Arial,Sans-Serif;
        }
        .nodeLevel3
        {
            font:10px Arial,Sans-Serif;
        }        
    </style>
    <title>TreeView Level Styles</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    <asp:TreeView
        id="TreeView1"
        Runat="server">
        <LevelStyles>
        <asp:TreeNodeStyle CssClass="nodeLevel1" />
        <asp:TreeNodeStyle CssClass="nodeLevel2" />
        <asp:TreeNodeStyle CssClass="nodeLevel3" />
        </LevelStyles>
        <Nodes>
        <asp:TreeNode
            Text="Home">
            <asp:TreeNode Text="Products">
                <asp:TreeNode Text="First Product" />
                <asp:TreeNode Text="Second Product" />
            </asp:TreeNode>
            <asp:TreeNode Text="Services">
                <asp:TreeNode Text="First Service" />
                <asp:TreeNode Text="Second Service" />
            </asp:TreeNode>    
        </asp:TreeNode>    
        </Nodes>
    </asp:TreeView>    
    
    
    </div>
    </form>
</body>
</html>



Treeview with custom icon (VB.net)

<%@ Page Language=VB Debug=true %>
<%@ Import Namespace="Microsoft.Web.UI.WebControls" %>
<%@ Register TagPrefix="IEControls" 
    Namespace="Microsoft.Web.UI.WebControls" 
    Assembly ="Microsoft.Web.UI.WebControls"
%>
<HTML>
<HEAD>
<TITLE>TreeView 2 Control Sample Page</TITLE>
</HEAD>
<BODY >
<form runat="server">
<Font Face="Tahoma">
<IEControls:treeview
    id="MyTree2"
    AutoSelect="True"
    ExpandLevel=0
    ImageURL="3.ico"
    ExpandedImageURL="Smile.ico"
    SelectedImageURL="4.ico"
    ShowLines="False"
    Indent="40"
    runat="server">
    <IEControls:treenode Text="A">
        <IEControls:treenode Text="A1"/>
        <IEControls:treenode Text="A2"/>
        <IEControls:treenode Text="A3">
            <IEControls:treenode Text="A31"/>
            <IEControls:treenode Text="A32"/>
            <IEControls:treenode Text="A33"/>
        </IEControls:treenode>
    </IEControls:treenode>
    <IEControls:treenode Text="B">
        <IEControls:treenode Text="B1"/>
        <IEControls:treenode Text="B2"/>
        <IEControls:treenode Text="B3"/>
        <IEControls:treenode Text="B4"/>
    </IEControls:treenode>
</IEControls:treeview>
</Font>
</Form>
</BODY>
</HTML>



treeview with expand, collapse and change action (VB.net)

<%@ Page Language=VB Debug=true %>
<%@ Import Namespace="Microsoft.Web.UI.WebControls" %>
<%@ Register TagPrefix="IEControls" 
    Namespace="Microsoft.Web.UI.WebControls" 
    Assembly ="Microsoft.Web.UI.WebControls"
%>
<script runat=server>
Sub TreeChange(ByVal Sender as Object, _
    ByVal E as TreeViewSelectEventArgs)
    lblMessage.Text = "You selected node " & E.NewNode.ToString() _
        & " and moved from node " & E.OldNode.ToString() & "."
End Sub
Sub TreeExpand(ByVal Sender as Object, _
    ByVal E as TreeViewClickEventArgs)
    lblMessage2.Text = "You expanded node " _
        & E.Node.ToString() & "."
End Sub
Sub TreeCollapse(ByVal Sender as Object, _
    ByVal E as TreeViewClickEventArgs)
    lblMessage2.Text = "You collapsed node " _
        & E.Node.ToString() & "."
End Sub
</SCRIPT>
<HTML>
<HEAD>
<TITLE>TreeView 3 Control Sample Page</TITLE>
</HEAD>
<BODY>
<form runat="server">
<Font Face="Tahoma">
<asp:Label
    id="lblMessage"
    runat="server"
/>
<BR>
<asp:Label
    id="lblMessage2"
    runat="server"
/>
<BR><BR>
<IEControls:treeview
    id="MyTree3"
    onSelectedIndexChanged="TreeChange"
    onexpand="TreeExpand" 
    oncollapse="TreeCollapse" 
    AutoPostBack="True"
    BackColor="LightYellow"
    BorderStyle=9
    BorderWidth=3
    BorderColor="DarkBlue"
    runat="server">
    <IEControls:treenode Text="A">
        <IEControls:treenode Text="A1"/>
        <IEControls:treenode Text="A2"/>
        <IEControls:treenode Text="A3">
            <IEControls:treenode Text="A31"/>
            <IEControls:treenode Text="A32"/>
            <IEControls:treenode Text="A33"/>
        </IEControls:treenode>
    </IEControls:treenode>
    <IEControls:treenode Text="B">
        <IEControls:treenode Text="B1"/>
        <IEControls:treenode Text="B2"/>
        <IEControls:treenode Text="B3"/>
        <IEControls:treenode Text="B4"/>
    </IEControls:treenode>
</IEControls:treeview>
</Font>
</Form>
</BODY>
</HTML>



Treeview with navigational URL (VB.net)

<%@ Page Language=VB Debug=true %>
<%@ Import Namespace="Microsoft.Web.UI.WebControls" %>
<%@ Register TagPrefix="IEControls" 
    Namespace="Microsoft.Web.UI.WebControls" 
    Assembly ="Microsoft.Web.UI.WebControls"
%>
<script runat=server>
Sub TreeChange(ByVal Sender as Object, _
    ByVal E as TreeViewSelectEventArgs)
    lblMessage.Text = "You selected node " & E.NewNode.ToString() _
        & " and moved from node " & E.OldNode.ToString() & "."
End Sub
Sub TreeExpand(ByVal Sender as Object, _
    ByVal E as TreeViewClickEventArgs)
    lblMessage2.Text = "You expanded node " _
        & E.Node.ToString() & "."
End Sub
Sub TreeCollapse(ByVal Sender as Object, _
    ByVal E as TreeViewClickEventArgs)
    lblMessage2.Text = "You collapsed node " _
        & E.Node.ToString() & "."
End Sub
</SCRIPT>
<HTML>
<HEAD>
<TITLE>TreeView 4 Control Sample Page</TITLE>
</HEAD>
<BODY>
<form runat="server">
<Font Face="Tahoma">
<asp:Label
    id="lblMessage"
    runat="server"
/>
<BR>
<asp:Label
    id="lblMessage2"
    runat="server"
/>
<BR><BR>
<IEControls:treeview
    id="MyTree4"
    onSelectedIndexChanged="TreeChange"
    onexpand="TreeExpand" 
    oncollapse="TreeCollapse" 
    AutoPostBack="True"
    BackColor="LightYellow"
    BorderStyle=9
    BorderWidth=3
    BorderColor="DarkBlue"
    runat="server">
    <IEControls:treenode Text="Clothing">
        <IEControls:treenode 
            Text="Men"s"
            Target="New"
            NavigateURL="./department.aspx?ID=2"
            />
        <IEControls:treenode Text="Women"s"
            Target="New"
            NavigateURL="./department.aspx?ID=3"
            />
        <IEControls:treenode Text="Children"s&nbsp&nbsp&nbsp">
            <IEControls:treenode 
                CheckBox=True 
                Text="Socks"
            />
            <IEControls:treenode 
                CheckBox=True 
                Text="Shirts"
            />
            <IEControls:treenode 
                CheckBox=True 
                Text="Pants"
                Checked
                />
        </IEControls:treenode>
    </IEControls:treenode>
    <IEControls:treenode Text="Electronics">
        <IEControls:treenode 
            CheckBox=True 
            Text="Audio"
            />
        <IEControls:treenode 
            CheckBox=True 
            Text="TV/VCR"
            />
        <IEControls:treenode
            CheckBox=True 
            Text="Computers"
            />
    </IEControls:treenode>
</IEControls:treeview>
</Font>
</Form>
</BODY>
</HTML>



Tree with style (C#)

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <style type="text/css">
        .treeNode
        {
            color:blue;
            font:14px Arial, Sans-Serif;
        }
        .rootNode
        {
            font-size:18px;
            width:100%;
            border-bottom:Solid 1px black;
        }
        .leafNode
        {
            border:Dotted 2px black;
            padding:4px;
            background-color:#eeeeee;
            font-weight:bold;
        }
    </style>
    <title>TreeView Styles</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    <asp:TreeView
        id="TreeView1"
        NodeStyle-CssClass="treeNode"
        RootNodeStyle-CssClass="rootNode"
        LeafNodeStyle-CssClass="leafNode"
        Runat="server">
        <Nodes>
        <asp:TreeNode
            Text="Home">
            <asp:TreeNode Text="Products">
                <asp:TreeNode Text="First Product" />
                <asp:TreeNode Text="Second Product" />
            </asp:TreeNode>
            <asp:TreeNode Text="Services">
                <asp:TreeNode Text="First Service" />
                <asp:TreeNode Text="Second Service" />
            </asp:TreeNode>    
        </asp:TreeNode>    
        </Nodes>
    </asp:TreeView>    
    
    
    </div>
    </form>
</body>
</html>



Using Images with TreeNode Controls in a TreeView Control (VB.net)

<%@ Page Language=VB Debug=true %>
<%@ Import Namespace="Microsoft.Web.UI.WebControls" %>
<%@ Register TagPrefix="IEControls" 
    Namespace="Microsoft.Web.UI.WebControls" 
    Assembly ="Microsoft.Web.UI.WebControls"
%>
<HTML>
<HEAD>
<TITLE>Using Images with TreeNode Controls in a TreeView Control</TITLE>
</HEAD>
<BODY LEFTMARGIN="40">
<form runat="server">
<IEControls:treeview
    id="tvBasic"
    runat="server"
    imageurl="3.ico"
    expandedimageurl="Smile.ico"
    selectedimageurl="4.ico"
>
    <IEControls:treenode Text="Clothing">
        <IEControls:treenode Text="Men"s"/>
        <IEControls:treenode Text="Women"s"/>
        <IEControls:treenode Text="Children"s">
            <IEControls:treenode Text="Socks"/>
            <IEControls:treenode Text="Shirts"/>
            <IEControls:treenode Text="Pants"/>
        </IEControls:treenode>
    </IEControls:treenode>
    <IEControls:treenode Text="Electronics">
        <IEControls:treenode Text="TV/VCR"/>
        <IEControls:treenode Text="Audio"/>
        <IEControls:treenode Text="Car"/>
        <IEControls:treenode Text="Computer"/>
    </IEControls:treenode>
</IEControls:treeview>
</form>
</BODY>
</HTML>



Using Links with TreeNode Controls in a TreeView Control (VB.net)

<%@ Page Language=VB Debug=true %>
<%@ Import Namespace="Microsoft.Web.UI.WebControls" %>
<%@ Register TagPrefix="IEControls" 
    Namespace="Microsoft.Web.UI.WebControls" 
    Assembly ="Microsoft.Web.UI.WebControls"
%>
<HTML>
<HEAD>
<TITLE>Using Links with TreeNode Controls in a TreeView Control</TITLE>
</HEAD>
<BODY LEFTMARGIN="40">
<form runat="server">
<IEControls:treeview
    id="tvBasic"
    autoselect="False"
    showplus="True"
    showlines="True"
    expandlevel=2
    runat="server">
    <IEControls:treenode Text="Search Engines">
        <IEControls:treenode 
            text="nfex.ru"
            target="_blank"
            navigateurl="http://www.nfex.ru"
        />
        <IEControls:treenode 
            text="Yahoo"
            target="_blank"
            navigateurl="http://www.yahoo.ru"
        />
        <IEControls:treenode 
            text="Excite"
            target="_blank"
            navigateurl="http://www.excite.ru"
        />
    </IEControls:treenode>
</IEControls:treeview>
</form>
</BODY>
</HTML>



Working with TreeNode Controls in a TreeView Control (VB.net)

<%@ Page Language=VB Debug=true %>
<%@ Import Namespace="Microsoft.Web.UI.WebControls" %>
<%@ Register TagPrefix="IEControls" 
    Namespace="Microsoft.Web.UI.WebControls" 
    Assembly ="Microsoft.Web.UI.WebControls"
%>
<HTML>
<HEAD>
<TITLE>Working with TreeNode Controls in a TreeView Control</TITLE>
</HEAD>
<BODY LEFTMARGIN="40">
<form runat="server">
<IEControls:treeview
    id="tvBasic"
    autoselect="False"
    showplus="True"
    showlines="True"
    expandlevel=2
    runat="server">
    <IEControls:treenode Text="Clothing">
        <IEControls:treenode Text="A"/>
        <IEControls:treenode Text="B"/>
        <IEControls:treenode Text="C">
            <IEControls:treenode Text="a"/>
            <IEControls:treenode Text="b"/>
            <IEControls:treenode Text="c"/>
        </IEControls:treenode>
    </IEControls:treenode>
    <IEControls:treenode Text="Electronics">
        <IEControls:treenode Text="A"/>
        <IEControls:treenode Text="B"/>
        <IEControls:treenode Text="C"/>
        <IEControls:treenode Text="D"/>
    </IEControls:treenode>
</IEControls:treeview>
</form>
</BODY>
</HTML>