Export (0) Print
Expand All
1 out of 2 rated this helpful - Rate this topic

Menu.FindItem Method

Retrieves the menu item at the specified value path.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)
public MenuItem FindItem(
	string valuePath


Type: System.String

The value path to the menu item to retrieve.

Return Value

Type: System.Web.UI.WebControls.MenuItem
A MenuItem that represents the menu item at the specified value path.

Use the FindItem method to retrieve a MenuItem object from the Menu control. To retrieve the MenuItem object, you must specify a menu path to the menu item. The menu path is a string of delimited values that form the path from a root menu item to the current menu item. To determine the delimiter character, use the PathSeparator property.

The following code example demonstrates how to use the FindItem method to retrieve a menu item from a Menu control at a specified value path.

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

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

  void Page_Load(Object sender, EventArgs e)
    // The value path for a menu item is a delimited list
    // of menu text values that form a path from the root 
    // menu item to the current menu item.

    // Declare the value path to the Classical menu item using
    // the delimiter character specified in the PathSeparator
    // property. In this example, the delimiter character is a
    // comma.
    String valuePath = "Home,Music,Classical";

    // Use the FindItem method to get the Classical menu item using
    // its value path.
    MenuItem item = NavigationMenu.FindItem(valuePath);

    // Indicate whether the menu item was found.
    if (item != null)
      Message.Text = item.Text + " menu item found at depth " + 
        item.Depth.ToString() + ".";
      Message.Text = "Menu item not found.";


<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>Menu PathSeparator and FindItem Example</title>
    <form id="form1" runat="server">

      <h3>Menu PathSeparator and FindItem Example</h3>

      <!-- Use the PathSeparator property to  -->
      <!-- change the delimiter character for -->
      <!-- the value path of a menu item to a -->
      <!-- comma (,).                         -->
      <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

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
© 2014 Microsoft. All rights reserved.