Overview
Data Binding is achieved by setting the DataSource property and calling the DataBind() method. If you are using declarative data sources such as AccessDataSource or SiteMapDataSource, databinding is achieved by specifying the DataSourceID.
 |
You can get a working demo application on Data Binding from our code library here. |
Usually, you would also want to do one or some of the following:
- Set Text, Value or NavigateUrl properties using:
- DataTextField - Gets or sets the field of the data source that provides the Text of the menu items.
- DataNavigateUrlField - Gets or sets the field of the data source that provides the NavigateUrl of the menu items.
-
DataValueField - Gets or sets the field of the data source that provides the
Value of the menu items
- Set other properties
Properties other than the above three (Text, Value and NavigateUrl) can be set in the ItemDataBound event:
| C# |
Copy Code |
|
protected void RadMenu1_ItemDataBound(object sender, Telerik.WebControls.RadMenuEventArgs e) { e.Item.ToolTip ="Read more about " + (string)DataBinder.Eval(e.Item.DataItem, "Text"); } |
| VB.NET |
Copy Code |
|
Protected Sub RadMenu1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.WebControls.RadMenuEventArgs) e.Item.ToolTip = "Read more about " + CStr(DataBinder.Eval(e.Item.DataItem, "Text")) End Sub
|
- Establish hierarchy through ID to ParentID relationship using:
- DataFieldID - The name of the DataColumn holding the ID value.
- DataFieldParentID - The name of the DataColumn holding the ParentID value. The id of the root items should be null.
With respect to binding to Telerik RadMenu, data sources can be divided into two major categories:
1. Data Sources from which Telerik RadMenu can create menu item hierarchy
 |
When the menu is bound to such data sources it can have not only root items, but also child items:
root 1 root 2
-child 2.1
-child 2.2 -child 2.2.1
-child 2.2.2 |
-
Data Sources from which Telerik RadMenu will automatically create menu item hierarchy:
-
XmlDataSource
-
SiteMapDataSource
- Data Sources which require the ID to ParentID relationship to establish hierarchy:
 |
The ID to ParentID relationship is established by setting the DataFieldID and DataFieldParentID properties |
2. Data Sources from which Telerik RadMenu cannot create menu item hierarchy
 |
When the menu is bound to such Data Sources it is flat, i.g. it has only root items
root 1 root 2 root 3
Setting DataFieldID and DataFieldParentID will have no effect. |
See Also