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 treeview items.
- DataNavigateUrlField - Gets or sets the field of the data source that provides the NavigateUrl of the treeview items.
-
DataValueField - Gets or sets the field of the data source that provides the
Value of the treeview items
- Set other properties
Properties other than the above three (Text, Value and NavigateUrl) can be set in the NodeBound event:
| C# |
Copy Code |
|
protected void RadTreeView1_NodeBound(object o, RadTreeNodeEventArgs e) { e.NodeBound.ToolTip ="Read more about " + (string)DataBinder.Eval(e.Item.DataItem, "Text"); } |
| VB.NET |
Copy Code |
|
Protected Sub RadTreeView1_NodeBound(ByVal o As Object, ByVal e As RadTreeNodeEventArgs) e.NodeBound.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 nodes should be null.
With respect to binding to Telerik RadTreeView, data sources can be divided into two major categories:
1. Data Sources from which Telerik RadTreeView can create treeview item hierarchy
 |
When the treeview is bound to such data sources it can have not only root items, but also child items:
- root node 1
+ child node 1.1
+ child node 1.2 |
-
Data Sources from which Telerik RadTreeView will automatically create treeview 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 RadTreeView cannot create treeview item hierarchy
 |
When the treeview is bound to such Data Sources it is flat, i.g. it has only root items
- root node 1
- root node 2
Setting DataFieldID and DataFieldParentID will have no effect. |
See Also