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