MenuItem.ValuePath Property


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Gets the path from the root menu item to the current menu item.

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

public string ValuePath { get; }

Property Value

Type: System.String

A delimiter-separated list of menu item values that form a path from the root menu item to the current menu item.

The ValuePath property contains a delimiter-separated list of menu item values that form a path from the root menu item to the current menu item. The value path is used to indicate the position of a menu item in a Menu control. You can specify the delimiter character used to separate the menu item values by using the PathSeparator property. This value is commonly used when parsing the list for the individual values, or to pass as an argument to the FindItem method of the TreeView class. Depending on the value displayed in the Menu 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.


The values of the Value property of each menu item from the root menu item to the current menu item are used to generate the value path. Menu items at the same menu level must each have a unique value for the Value property; the Menu control cannot distinguish between different menu items at the same level that have the same value.

The following example demonstrates how to parse the value to the ValuePath property for the individual menu item values.

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

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

  void Page_Load(Object sender, EventArgs e)
    // Get the Classical menu item using the Items
    // and ChildItems collections.
    MenuItem item = NavigationMenu.Items[0].ChildItems[0].ChildItems[0];

    // Create the delimiter array using the PathSeparator value.
    // This array is used by the the Split method to parse the
    // value path string. 
    Char[] DelimiterArray = new Char[1];
    DelimiterArray[0] = NavigationMenu.PathSeparator;

    // Parse the value path of the Classical menu item 
    // using the Split method.
    String[] nodeValues = item.ValuePath.Split(DelimiterArray);

    // Display the original and parsed values.
    Message.Text = "The original value path for the Classical menu item is <b>" + 
      item.ValuePath + "</b>.<br/>";
    Message.Text += "The individual values that make up the value " +
      "path are: <br/>";

    foreach (String menuValue in nodeValues)
      Message.Text += "- <b>" + menuValue + "</b><br/>";


<html xmlns="" >
  <head runat="server">
    <title>MenuItem ValuePath Example</title>
    <form id="form1" runat="server">

      <h3>MenuItem ValuePath Example</h3>

      <asp:menu id="NavigationMenu"

          <asp:menuitem text="Home"
            <asp:menuitem text="Music"
              <asp:menuitem text="Classical"
              <asp:menuitem text="Rock"
              <asp:menuitem text="Jazz"
            <asp:menuitem text="Movies"
              <asp:menuitem text="Action"
              <asp:menuitem text="Drama"
              <asp:menuitem text="Musical"



      <asp:label id="Message" 


.NET Framework
Available since 2.0
Return to top