TreeNodeEventHandler Delegate

Note: This delegate is new in the .NET Framework version 2.0.

Represents the method that will handle the TreeNodeCollapsed, TreeNodeDataBound, TreeNodeExpanded, or TreeNodePopulate event of the TreeView control.

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

public delegate void TreeNodeEventHandler (
	Object sender,
	TreeNodeEventArgs e
/** @delegate */
public delegate void TreeNodeEventHandler (
	Object sender, 
	TreeNodeEventArgs e
JScript supports the use of delegates, but not the declaration of new ones.



The source of the event.


A TreeNodeEventArgs that contains the event data.

When you create a TreeNodeEventHandler delegate, you identify the method that will handle the event. To associate the event with your event handler, add an instance of the delegate to the event. The event handler is called whenever the event occurs, unless you remove the delegate. For more information about event-handler delegates, see Events and Delegates.

The following code example demonstrates how to use the TreeNodeEventHandler delegate to register an event-handling method programmatically.

<%@ Page Language="C#" %>

<script runat="server">

  void Page_Load(Object sender, EventArgs e)

    // Create a new TreeView control.
    TreeView NewTree = new TreeView();

    // Set the properties of the TreeView control.
    NewTree.ID = "BookTreeView";
    NewTree.DataSourceID = "BookXmlDataSource";

    // Create the tree node binding relationship.

    // Create the root node binding.
    TreeNodeBinding RootBinding = new TreeNodeBinding();
    RootBinding.DataMember = "Book";
    RootBinding.TextField = "Title";

    // Create the parent node binding.
    TreeNodeBinding ParentBinding = new TreeNodeBinding();
    ParentBinding.DataMember = "Chapter";
    ParentBinding.TextField = "Heading";

    // Create the leaf node binding.
    TreeNodeBinding LeafBinding = new TreeNodeBinding();
    LeafBinding.DataMember = "Section";
    LeafBinding.TextField = "Heading";

    // Add bindings to the DataBindings collection.

    // Manually register the event handler for the TreeNodeExpanded event.
    NewTree.TreeNodeExpanded += new TreeNodeEventHandler(this.Node_Expand);

    // Add the TreeView control to the Controls collection of the PlaceHolder control.


  void Node_Expand(Object sender, TreeNodeEventArgs e)

    // Display the expanded node.
    Message.Text = "You expanded: " + e.Node.Text;



    <form runat="server">
      <h3>TreeView TreeNodeEventHandler Example</h3>
      <asp:PlaceHolder id="ControlPlaceHolder" runat="server">
      <asp:XmlDataSource id="BookXmlDataSource"  
      <asp:Label id="Message" runat="server"/>

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions