This documentation is archived and is not being maintained.

TreeView.FindNode Method

Retrieves the TreeNode object in the TreeView control at the specified value path.

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

public TreeNode FindNode(
	string valuePath


Type: System.String
The value path of a node.

Return Value

Type: System.Web.UI.WebControls.TreeNode
The TreeNode at the specified value path.

Use the FindNode method to get a node from the TreeView control at the specified value path. The value path contains a delimiter-separated list of node values that form a path from the root node to the current node. Each node stores its value path in the ValuePath property. The PathSeparator property specifies the delimiter character that is used to separate the node values.

The following code example demonstrates how to use the FindNode method to retrieve a node from the TreeView control.

Security noteSecurity Note

This example has a text box that accepts user input, which is a potential security threat. By default, ASP.NET Web pages validate that user input does not include script or HTML elements. For more information, see Script Exploits Overview.

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

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

  void Button_Click(Object sender, EventArgs e)

    // Find the node specified by the user.
    TreeNode node = LinksTreeView.FindNode(Server.HtmlEncode(ValuePathText.Text));

    if (node != null)
      // Indicate that the node was found.
      Message.Text = "The specified node (" + node.ValuePath + ") was found.";
      // Indicate that the node is not in the TreeView control.
      Message.Text = "The specified node (" + ValuePathText.Text + ") is not in this TreeView control.";



<html xmlns="">
  <head runat="server">
    <title>TreeView FindNode Example</title>
    <form id="form1" runat="server">

      <h3>TreeView FindNode Example</h3>

      <asp:TreeView id="LinksTreeView"
        Font-Names= "Arial"


          <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" Value="Chapter One">

              <asp:TreeNode Text="Section 1.0" Value="Section 1.0">

                <asp:TreeNode Text="Topic 1.0.1" Value="Topic 1.0.1"/>
                <asp:TreeNode Text="Topic 1.0.2" Value="Topic 1.0.2"/>
                <asp:TreeNode Text="Topic 1.0.3" Value="Topic 1.0.3"/>


              <asp:TreeNode Text="Section 1.1">

                <asp:TreeNode Text="Topic 1.1.1" Value="Topic 1.1.1"/>
                <asp:TreeNode Text="Topic 1.1.2" Value="Topic 1.1.2"/>
                <asp:TreeNode Text="Topic 1.1.3" Value="Topic 1.1.3"/>
                <asp:TreeNode Text="Topic 1.1.4" Value="Topic 1.1.4"/>



            <asp:TreeNode Text="Chapter Two" Value="Chapter Two">

              <asp:TreeNode Text="Section 2.0" Value="Section 2.0">

                <asp:TreeNode Text="Topic 2.0.1" Value="Topic 2.0.1"/>
                <asp:TreeNode Text="Topic 2.0.2" Value="Topic 2.0.2"/>



          <asp:TreeNode Text="Appendix A" />
          <asp:TreeNode Text="Appendix B" />
          <asp:TreeNode Text="Appendix C" />





      Enter the value path of the node to locate. <br/>
      Use a forward slash (/) to delimit each node value.<br/>
      <asp:TextBox id="ValuePathText" 
        Text="Table of Contents/Chapter One/Section 1.0"


      <asp:Button id="Submit"
        Text="Find Node"


      <asp:Label id="Message" runat="server"/>


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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