This documentation is archived and is not being maintained.

TreeView.TreeNodeCheckChanged Event

Occurs when a check box in the TreeView control changes state between posts to the server.

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

public event TreeNodeEventHandler TreeNodeCheckChanged
/** @event */
public void add_TreeNodeCheckChanged (TreeNodeEventHandler value)

/** @event */
public void remove_TreeNodeCheckChanged (TreeNodeEventHandler value)

In JScript, you can handle the events defined by a class, but you cannot define your own.
Not applicable.

The TreeNodeCheckChanged event is raised when a check box in the TreeView control changes state between posts to the server. This allows you to provide an event-handling method that performs a custom routine, such as updating a database or the displayed content, whenever this event occurs.

Even though the TreeNodeCheckChanged event is fired on post back, changing a check box does not cause a post back.

For more information about handling events, see Consuming Events.

The following code example demonstrates how to use the TreeNodeCheckChanged event to update a Label control when the check boxes of the TreeView control change state between posts to the server.

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<script runat="server">

  void LinksTreeView_CheckChanged(Object sender, TreeNodeEventArgs e)

    if(LinksTreeView.CheckedNodes.Count > 0)

      // Clear the message label.
      Message.Text = "You selected: <br /><br />";

      // Iterate through the CheckedNodes collection and display 
      // the selected nodes.
      foreach (TreeNode node in LinksTreeView.CheckedNodes)

        Message.Text += node.Text + "<br />";




      Message.Text = "No items selected.";




<html xmlns="" >
  <head runat="server">
    <title>TreeView CheckChanged Example</title>
    <form id="form1" runat="server">
      <h3>TreeView CheckChanged Example</h3>
      <!-- Set the ShowCheckBoxes property declaratively.   -->
      <!-- Because the ShowCheckBoxes property uses a flag  -->
      <!-- enumeration, you can combine multiple values by  -->
      <!-- using the bitwise OR operator. In declarative    -->
      <!-- syntax, this is done using a comma separated     -->
      <!-- list.                                            -->  
      <asp:TreeView id="LinksTreeView"
          <asp:TreeNodeStyle ChildNodesPadding="10" 
          <asp:TreeNodeStyle ChildNodesPadding="5" 
          <asp:TreeNodeStyle ChildNodesPadding="5" 
          <asp:TreeNodeStyle ChildNodesPadding="10" 
          <asp:TreeNode Text="Table of Contents"
            <asp:TreeNode Text="Chapter One">
              <asp:TreeNode Text="Section 1.0">
                <asp:TreeNode Text="Topic 1.0.1"/>
                <asp:TreeNode Text="Topic 1.0.2"/>
                <asp:TreeNode Text="Topic 1.0.3"/>
              <asp:TreeNode Text="Section 1.1">
                <asp:TreeNode Text="Topic 1.1.1"/>
                <asp:TreeNode Text="Topic 1.1.2"/>
                <asp:TreeNode Text="Topic 1.1.3"/>
                <asp:TreeNode Text="Topic 1.1.4"/>
            <asp:TreeNode Text="Chapter Two">
              <asp:TreeNode Text="Section 2.0">
                <asp:TreeNode Text="Topic 2.0.1"/>
                <asp:TreeNode Text="Topic 2.0.2"/>
          <asp:TreeNode Text="Appendix A" />
          <asp:TreeNode Text="Appendix B" />
          <asp:TreeNode Text="Appendix C" />
      <br /><br />
      <asp:Button id="Submit"
        Text="Select Items"
      <br /><br />
      <asp:Label id="Message"


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

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0