TreeNode.ValuePath Property

Gets the path from the root node to the current node.

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

[BrowsableAttribute(false)]
public string ValuePath { get; }

Property Value

Type: System.String
A delimiter-separated list of node values that form a path from the root node to the current node.

The ValuePath property contains a delimiter-separated list of node values that form a path from the root node to the current node. Use the PathSeparator property to specify the delimiter character used to separate the node values. This value is commonly used when parsing the list for the individual values, or to pass as an argument to the FindNode method of the TreeView class.

Depending on the value displayed in the TreeView control, the delimiter character might need to be changed to prevent any conflicts. For example, if you set the delimiter character to a comma, the displayed value should not contain any commas; otherwise, you cannot accurately parse the ValuePath property.

NoteNote

Nodes at the same level must each have a unique value for the Value property; the TreeView control cannot distinguish between different nodes at the same level that have the same value. In this scenario, if the user clicks a node that has a duplicate value, the node that appears first in the TreeView control is selected.

The following code example demonstrates how to parse the ValuePath property.



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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  void Index_Changed(Object sender, EventArgs e)
  {

    // Set the PathSeparator character based on the user's selection.
    // Notice that the value must be converted to a Char data type.
    BookTreeView.PathSeparator = Convert.ToChar(List.SelectedItem.Text);

    // Display the ValuePath values for the second-level nodes.
    Message.Text = "The ValuePath values for the second-level nodes are:<br />";
    foreach(TreeNode node in BookTreeView.Nodes[0].ChildNodes)
    {

      // Create the delimiter array with the PathSeparator value for the Split method.
      Char[] DelimiterArray = new Char[1];
      DelimiterArray[0] = BookTreeView.PathSeparator;

      // Parse the ValuePath value using the delimiter array.
      String[] NodeValues = node.ValuePath.Split(DelimiterArray);

      // Display the node values.
      for(int i=0; i<NodeValues.Length; i++)
      {
        if(i != NodeValues.Length - 1)
        {   
          // Append the delimiter character.
          Message.Text += NodeValues[i] + BookTreeView.PathSeparator.ToString();
        }
        else
        {
          // Do not append the delimiter character.
          Message.Text += NodeValues[i];
        }

      }

      // Append a line break for the next node.
      Message.Text += "<br />";

    }

  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >

  <head runat="server">
    <title>TreeView PathSeparator Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>TreeView PathSeparator Example</h3>

      <asp:TreeView id="BookTreeView"
        ExpandDepth="-1"
        PathSeparator="/"
        runat="server">

        <Nodes>

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

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

              <asp:TreeNode Value="Paragraph 1" 
                Text="Paragraph 1">
              </asp:TreeNode>

            </asp:TreeNode>

            <asp:TreeNode Value="Section 2" 
              Text="Section 2">
            </asp:TreeNode>

          </asp:TreeNode>

        </Nodes>

      </asp:TreeView>

      <br />

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

      <hr />

      Select a path separator value:<br />

      <asp:DropDownList ID="List"
        AutoPostBack="true"
        OnSelectedIndexChanged="Index_Changed"   
        runat="server">

        <asp:ListItem Selected="true">/</asp:ListItem>
        <asp:ListItem>\</asp:ListItem>
        <asp:ListItem>|</asp:ListItem>
        <asp:ListItem>,</asp:ListItem>
        <asp:ListItem>;</asp:ListItem>

      </asp:DropDownList>

    </form>
  </body>
</html>



.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.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft