RadMenu for ASP.NET

Data Bindings Send comments on this topic.
See Also
New to Telerik RadMenu? > Design-time support > Data Bindings

Glossary Item Box

The DataBindings property of RadMenu is a collection that defines the relationship between a data item and the menu item it is binding to. In other words, the DataBindings collection allows you to 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  depth, a data member, or both. (See Important notes about DataBindings properties below.)

DataBindings is fully controllable from the Visual Studio designer. Using the DataBindings design-time interface, you do not need to write any code when binding your menu. 

ASPX structure of a menu with the DataBindings property set

In the ASPX page, the DataBindings collection resides within the <rad:RadMenu> and </rad:RadMenu> tags. For example:

  Copy Code
<rad:RadMenu ID="RadMenu1" runat="server" DataSourceID="AccessDataSource1"
   
DataFieldID="id" DataFieldParentID="parentId" DataTextField="Text">
   
<DataBindings>
       
<rad:MenuItemBinding EnabledField="" ImageUrl="" ImageUrlField="" NavigateUrl=""
           
NavigateUrlField="" Selectable="True" SelectableField="" Target="" TargetField=""
           
TextField="Text" ToolTip="" Value="" ValueField="" Depth="" ToolTipField="" />
   
</DataBindings>
</
rad:RadMenu>

How to enable DataBindings

  1. Make sure all of the following properties of RadMenu are set accordingly:
    • DataSourceID - to the instance of the data source you want to bind the menu to;
    • DataTextField - to the data column you want to use for populating your items with text;
      The DataTextField property is optional. You can later set the TextField property of the DataBindings collection. (See below.) 
    • If you are building a hierarchical menu, also set:
      • DataFieldID - to the column containing the IDs of data fields corresponding to each menu item;
      • DataFieldParentID - to the column containing the parent IDs of the data fields, if any.
  2. From the Telerik RadMenu Smart Tag, select Edit MenuItem DataBindings. The MenuItemBinding Collection Editor dialog appears.

    The MenuItemBinding Collection Editor dialog

  3. Under Members, click Add to add one or more members. Two or more members are required if you want to bind different properties at different depth levels. (See Depth below.)
  4. Set the properties for each member. When ready, click OK.

Important notes about DataBindings properties

Depth
Gets or sets the menu depth to which binding is applied. Accepts a numeric value. (The root level depth is "0".) If the property is not set, the current collection member settings affect all levels.

Text vs TextField, Value vs ValueField, etc.
All properties ending with the suffix -Field can be databound to take their values from a corresponding field in the data source. Properties not ending with -Field are static: all MenuItem objects to which the MenuItemBinding object is applied share the same value.

For instance, if your database contains a column named Text and you set TextField="Text", the Text property of all menu items will take its value from the Text column in the database. Alternatively, if you set Text="Text", all your menu items will take the static string "Text" as the value of their Text property.

DataMember
When the data source contains multiple elements or tables, use the DataMember property to specify the element or table to bind to a menu item. 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.

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:

  Copy Code
<rad:MenuItemBinding DataMember="Item" Depth="1" TextField="Title">
<
rad: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.

If multiple MenuItemBinding objects are defined that conflict with each other, Telerik RadMenu 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.

For a step-by-step walkthrough of this functionality, see our example scenario.

See Also