IE control treeview with link node (C#) : Tree « Components « ASP.Net






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.ComponentModel;
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.java2s.com", "java2s.com", "Page",  
          rootNode.Nodes);
        AddNode("http://www.google.com", "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);

    }
  }


--%>
           
       








Related examples in the same category

1.IE control tree with link node and frame control (C#)
2.Tree with style (C#)
3.Static WebControls treeview (VB.net)
4.Treeview with custom icon (VB.net)
5.treeview with expand, collapse and change action (VB.net)
6.Treeview with navigational URL (VB.net)
7.Working with TreeNode Controls in a TreeView Control (VB.net)
8.Setting Styles in a TreeView Control (VB.net)
9.Tree Node selected event in a TreeView (VB.net)
10.Using Links with TreeNode Controls in a TreeView Control (VB.net)
11.Using Images with TreeNode Controls in a TreeView Control (VB.net)
12.TreeNode Expand action (VB.net)
13.TreeNode Collapses action (VB.net)
14.Treeview and checkbox treenode (VB.net)
15.On Tree Node Populate Event (C#)
16.Add tree node (C#)
17.Tree node with hyper link (C#)
18.Treeview image: XP file explore style (C#)
19.Tree view node style (C#)
20.On tree node selection changed event (C#)