Export (0) Print
Expand All

MenuItemBinding.Depth Property

Gets or sets the menu depth to which the MenuItemBinding object is applied.

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

[TypeConverterAttribute("System.Web.UI.Design.WebControls.TreeNodeBindingDepthConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public int Depth { get; set; }

Property Value

Type: System.Int32
The menu depth to which the MenuItemBinding is applied. The default is -1, which indicates that this property is not set.

When creating a MenuItemBinding object, you must specify the criteria for binding. The criteria indicate when a data item should be bound to a menu item. You can specify the Depth property, the DataMember property, or both.

Use the Depth property to specify the menu depth at which to apply the MenuItemBinding object. For example, the following MenuItemBinding declaration binds the Name and ID fields of the data source to the Text and Value properties, respectively, of all menu items with a depth of 0:

<asp:MenuItemBinding Depth="0" TextField="Name" ValueField="ID">

Sometimes you might need to create a menu item binding that specifies both a depth and a data member. This is often used when the data source contains items at different levels that have the same data member value. For example, you can have <Item> elements that appear at different levels within an XML file. The following MenuItemBinding declarations show how to specify menu item bindings that apply to identical data members at different menu depths:

<asp:MenuItemBinding DataMember="Item" Depth="1" TextField="Title">

<asp:MenuItemBinding DataMember="Item" Depth="2" TextField="ISBN">

If a menu item binding is defined without a depth and a data member, the menu item binding is applied to all menu items within the menu. This is commonly used when all data items have the same properties and should be displayed identically, regardless of the menu depth.

After the binding criteria are established, you can then bind a property of a MenuItem object that can be bound to a value. You can bind to a field of a data item or to a static value. When bound to a static value, all MenuItem objects to which the MenuItemBinding object is applied share the same value. Properties bound to fields contain the values of the field from the data source.

If conflicting MenuItemBinding objects are defined, the Menu control applies the menu item bindings in the following order of precedence:

  1. The MenuItemBinding object that defines and matches both a depth and a data member.

  2. The MenuItemBinding object that defines and matches the data member only.

  3. The MenuItemBinding object that defines and matches the depth only.

  4. The MenuItemBinding object that defines neither the depth nor the data member. (This type of menu item binding is applied to all menu items in the menu.)

  5. The MenuItemBinding object that does not have a match in the data source. In this case, the value returned by the ToString() method of the data item is then bound to the Text and Value properties of the menu items to which the MenuItemBinding object is applied.

The following code example demonstrates how to use the Depth property to specify the menu depth at which to apply a MenuItemBinding object. For this example to work correctly, you must copy the sample XML data below to a file named MenuDepth.xml.


<%@ page language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>MenuItemBinding Depth Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>MenuItemBinding Depth Example</h3>

      <asp:menu id="NavigationMenu"
        datasourceid="MenuSource"
        runat="server">

        <databindings>

          <asp:menuitembinding depth="0"
            textfield="Title"
            valuefield="Description"
            imageurlfield="ImageUrl"
            tooltipfield="ToolTip"
            target="_self" />
          <asp:menuitembinding depth="1"
            textfield="Title"
            valuefield="Description"
            imageurlfield="ImageUrl"
            tooltipfield="ToolTip"
            target="_blank"/>
          <asp:menuitembinding depth="2"
            textfield="Title"
            valuefield="Description"
            imageurlfield="ImageUrl"
            tooltipfield="ToolTip"
            target="_blank"/>

        </databindings>

      </asp:menu>

      <asp:xmldatasource id="MenuSource"
        datafile="MenuDepth.xml"
        runat="server"/> 

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

The following code is sample site map data for the previous example.

<MapNode ImageUrl="~\Images\Home.gif"

Title="Home"

Description="Root Page"

ToolTip="Home Page">

<MapNode ImageUrl="~\Images\Music.gif"

Title="Music"

Description="Music Category"

ToolTip="Music Page">

<MapNode ImageUrl="~\Images\Classical.gif"

Title="Classical"

Description="Classical Section"

ToolTip="Classical Page"/>

<MapNode ImageUrl="~\Images\Rock.gif"

Title="Rock"

Description="Rock Section"

ToolTip="Rock Page"/>

<MapNode ImageUrl="~\Images\Jazz.gif"

Title="Jazz"

Description="Jazz Section"

ToolTip="Jazz Page"/>

</MapNode>

<MapNode ImageUrl="~\Images\Movies.gif"

Title="Movies"

Description="Movies Category"

ToolTip="Movies Page">

<MapNode ImageUrl="~\Images\Action.gif"

Title="Action"

Description="Action Section"

ToolTip="Action Page"/>

<MapNode ImageUrl="~\Images\Drama.gif"

Title="Drama"

Description="Drama Section"

ToolTip="Drama Page"/>

<MapNode ImageUrl="~\Images\Musical.gif"

Title="Musical"

Description="Musical Section"

ToolTip="Musical Page"/>

</MapNode>

</MapNode>

.NET Framework

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

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.

Show:
© 2014 Microsoft