The DataBindings property of RadPanelBar is a collection that defines the relationship between a data item and the panel 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 panelbar item. The criteria can be specified with depth, 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 panelbar.
ASPX structure of a panelbar with the DataBindings property set
In the ASPX page, the DataBindings collection resides within the <rad:RadPanelBar> and </rad:RadPanelBar> tags. For example:
| |
Copy Code |
|
<rad:RadPanelBar ID="RadPanelBar1" runat="server" DataSourceID="AccessDataSource1" DataFieldID="id" DataFieldParentID="parentId" DataTextField="Text"> <DataBindings> <rad:RadPanelItemBinding EnabledField="" ImageUrl="" ImageUrlField="" NavigateUrl="" NavigateUrlField="" Selectable="True" SelectableField="" Target="" TargetField="" TextField="Text" ToolTip="" Value="" ValueField="" Depth="" ToolTipField="" /> </DataBindings> </rad:RadPanelBar> |
How to enable DataBindings
- Make sure all of the following properties of RadPanelBar are set accordingly:
- DataSourceID - to the instance of the data source you want to bind the panelbar 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 panelbar, also set:
- DataFieldID - to the column containing the IDs of data fields corresponding to each panelbar item;
- DataFieldParentID - to the column containing the parent IDs of the data fields, if any.
-
From the Telerik RadPanelBar Smart Tag, select Edit RadPanelItem DataBindings. The Collection Editor dialog appears: 
- 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.)
- Set the properties for each member. When ready, click OK.
Important notes about DataBindings properties
Depth
Gets or sets the panelbar 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 RadPanelItem objects to which the RadPanelItemBinding 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 panelbar items will take its value from the Text column in the database. Alternatively, if you set Text="Text", all your panelbar 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 panel 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 panel item binding that specifies both 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 panel item bindings that apply to identical data members at different panelbar depths:
| |
Copy Code |
|
<rad:RadPanelItemBinding DataMember="Item" Depth="1" TextField="Title"> <rad:RadPanelItemBinding DataMember="Item" Depth="2" TextField="ISBN"> |
If a panelbar item binding is defined without depth and a data member, the panel item binding is applied to all panel items within the panelbar. This is commonly used when all data items have the same properties and should be displayed identically, regardless of the panelbar depth.
After the binding criteria are established, you can then bind a property of a RadPanelItem 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 RadPanelItemBinding objects are defined that conflict with each other, Telerik RadPanelBar applies the panel item bindings in the following order of precedence:
- The RadPanelItemBinding object that defines both a depth and a data member.
- The RadPanelItemBinding object that defines only the depth.
- The RadPanelItemBinding object that defines only the data member.
- The RadPanelItemBinding object that defines neither the depth nor the data member.
|
See Also