RadTreeView fully supports binding to a wide range of datasources:
- DataSet, DataTable, DataView
- ASP 2.0 DataSource types including
- Hierarchical DataSource components
- Table-based DataSource components
- Any object that implements the IEnumerable interface
In addition, while not strictly data binding, RadTreeView can load XML content files.
You can easily populate your treeview instance with only a few lines of code. The
built-in data binding supports auto-binding from a a single self-referencing table
with ID -> ParentID relation.
Below are the properties and methods related to data binding:
DataSource - Set to an instance of your data source. This is mandatory when
binding the RadTreeView at runtime
DataSourceID - Set to the ID of your data source. This is mandatory when
binding the RadTreeView declaratively
DataMember - If the data source is a DataSet and DataMember is set, then
the RadTreeView is bound to the DataTable with the respective name in the DataSet.
If DataMember is not set, the RadTreeView is bound to the first DataTable in the
DataFieldID - This is the field name from the data source used to uniquely
identify each row. This field is required when binding to hierarchical data
DataFieldParentID - This is the field name from the data source used to identify
the row for the parent node. This field is required when binding to hierarchical
DataTextField - This is the field name from the data source that populates
each node's Text property during binding
DataValueField - This is the field name from the data source that populates
each node's Value property during binding
DataNavigateUrlField - This is the field name from the data source that populates
each node's NavigateUrlField property during binding
DataBind - Call this method after you have set the aforementioned properties
when binding at runtime. This method is mandatory for binding at runtime
MaxDataBindDepth - This property is used to determine the binding
depth. If for example you want to bind only the first two levels
of the treeview, you should set this property to 2. The default
value of the MaxDataBindDepth property is -1,
which means that all nodes will be bound. Marking the treeview instance with
MaxDataBindDepth="0" will NOT bind any nodes.
AppendDataBoundNodes - If you bind the treeview using the DataBind method,
all TreeNodes are automatically cleared. Setting AppendDataBoundNodes to
True preserves the nodes that are already present in the treeview. This lets
you bind RadTreeView to multiple data sources or use both unbound and bound modes.
If you need to map additional fields from the Data Source to properties of the RadTreeView
item, you can use the NodeDataBound event.
protected void RadTreeView1_NodeDataBound(object sender, RadTreeNodeEventArgs e)
e.Node.ToolTip = (e.Node.DataItem as DataRowView)["Description"].ToString();
Protected Sub RadTreeView1_NodeDataBound(ByVal sender As Object, ByVal e As RadTreeNodeEventArgs)
e.Node.ToolTip = (TryCast(e.Node.DataItem, DataRowView))("Description").ToString()