This documentation is archived and is not being maintained.

Menu.DataBindings Property

Gets a collection of MenuItemBinding objects that define the relationship between a data item and the menu item it is binding to.

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

public function get DataBindings () : MenuItemBindingCollection

Property Value

Type: System.Web.UI.WebControls.MenuItemBindingCollection
A MenuItemBindingCollection that represents the relationship between a data item and the menu item it is binding to.

The DataBindings collection contains MenuItemBinding objects that define the relationship between a data item and the menu item it is binding to. When binding to a data source where each data item contains multiple properties (such as an XML element with several attributes), a menu item displays the value returned by the ToString() method of the data item by default. In the case of an XML element, the menu item displays the element name, which shows the underlying structure of the tree, but is not very useful otherwise. You can bind a menu item to a specific data item property by specifying menu item bindings.

When defining the relationship between a data item and a menu item, you must specify both the criteria for binding and the property of a data item to bind to. The criteria indicate when a data item should be bound to a menu item. The criteria can be specified with a depth, a data member, or both. The depth specifies the menu level that gets bound. For example, if you specify a depth of 0, all menu items in the tree structure at level 0 are bound using the menu item binding. A data member specifies the type of the data item in the underlying data source, but can represent different information depending on the data source. For example, the data member for an XML element specifies the name of the element.

If multiple MenuItemBinding objects are defined that conflict with each other, the Menu control applies the menu item bindings in the following order of precedence:

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

  2. The MenuItemBinding object that defines only the depth.

  3. The MenuItemBinding object that defines only the data member.

  4. The MenuItemBinding object that defines neither the depth nor the data member.

Once the binding criteria are established, you can then bind a property of a MenuItem object that is able to be bound to an attribute or field of a data item. For example, you can bind the Text property of a menu item to the text attribute on an XML element by setting the TextField property of a MenuItemBinding object. You can also bind to a static value. If you set the Text property of a MenuItemBinding object, all menu items to which the MenuItemBinding object is applied share the same static text value. For more information on binding the properties of a MenuItem object to a value, see MenuItemBinding.

Although the DataBindings collection can be programmatically populated, it is usually set declaratively. To specify the menu item bindings, first nest opening and closing <DataBindings> tags between the opening and closing tags of the Menu control. Next, place <asp:MenuItemBinding> elements between the opening and closing <DataBindings> tags for each menu item binding you want to specify.

The following code example demonstrates how to use the DataBindings collection to define the relationship between the fields of an XmlDataSource control and the menu items in a Menu control. For this example to work correctly, you must copy the sample XML data below to a file named Map.xml.

No code example is currently available or this language may not be supported.

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

<MapHomeNode url="~\Home.aspx" 
  <MapNode url="~\Music.aspx"
    <MapNode url="~\Classical.aspx" 
    <MapNode url="~\Rock.aspx"
    <MapNode url="~\Jazz.aspx"
  <MapNode url="~\Movies.aspx"
    <MapNode url="~\Action.aspx"
    <MapNode url="~\Drama.aspx"
    <MapNode url="~\Musical.aspx"

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

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

.NET Framework

Supported in: 3.5, 3.0, 2.0