When using ObjectDataSource, you can bind RadMenu declaratively at design time. The SelectMethod of the ObjectDataSource should return an object that supports the IEnumerable or ICollection interface. Such collections include Array, ArrayList, and List.

If the SelectMethod returns a collection of strings, those strings are automatically mapped to the Text property of the respective menu items. If the collection contains objects (as opposed to string values), you can use the DataTextField, DataNavigateUrlField, and the DataValueField properties to map a property from the object directly to the Text, NavigateUrl and Value properties of RadMenuItem. If the DataFieldID and DataFieldParentID properties are set, RadMenu will create a hierarchy of Items, determining the Root ones using the following algorithm:

note

their DataFieldParentID property must be null if it is of nullable (e.g. int? ) or reference (e.g. string ) type.
-example:-
IDParentID
1 (null)
2 1

To map additional properties from the object to other properties of the respective menu item, use an ItemDataBound event handler. The event arguments passed to the event, e.Item and e.Item.DataItem, hold the instance of the menu item being bound and the DataItem associated with the menu item. You can map a property from the DataItem to the property of the RadMenuItem class (make sure to cast the DataItem object to your respective data type first).

The following example shows a RadMenu bound declaratively to an ObjectDataSource:

Instead of going through an ObjectDataSource, you can bind RadMenu directly to any collection that implements the ICollection or IEnumerable interface.Mapping properties of the objects in the collection to properties of the menu items works exactly the same way as when using ObjectDataSource.

To bind directly to a collection, you must bind the menu at runtime, using the following steps:

Create the collection.

Add items to the collection. Depending on the type of the collection, these can be strings, or more complex objects with properties that provide data for the various properties of RadMenuItem and/or for the ID -> ParentID relationship.

Set the DataSource property of RadMenu to the instance of the collection.

Call the DataBind method.

The following example shows a menu bound to an ArrayList. The list contains SiteDataItem objects with the same definition as in the ObjectDataSource example, only that their ParentID property is of nullable type - int?:

Give article feedback

Tell us how we can improve this article

Code samples are inaccurate/outdated.
I expected to find other/more information.
There are typos/broken links/broken page elements.
Content is inaccurate/outdated.
Other
By checking this box you consent to Progress contacting you by email about your response on this page.