RadTreeView for ASP.NET

DataBindings Send comments on this topic.
See Also
New to Telerik RadTreeView? > Getting started > Design-time Support > DataBindings

Glossary Item Box

The DataBindings property of RadTreeView is a collection that defines the relationship between a data item and the tree node 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 tree node. The criteria can be specified with a depth, a 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 treeview. 


ASPX structure of a treeview with the DataBindings property set


In the ASPX page, the DataBindings collection resides within the <rad:RadTreeView> and  </rad:RadTreeView> tags. For example:


How to enable DataBindings
 

  1. Make sure all the following properties of RadTreeView are set accordingly:
  2. DataSourceID - to the instance of the data source you want to bind the treeview to;
  3. DataTextField - to the data column you want to use for populating your nodes with text;
     

    The DataTextField property is optional. You can later set the TextField property of the DataBindings collection. (See below.) 

  4. If you are building a hierarchical treeview, also set:
  5. DataFieldID - to the column containing the IDs of data fields corresponding to each tree node;
  6. DataFieldParentID - to the column containing the parent IDs of the data fields, if any.
  7. From the Telerik RadTreeView Smart Tag, select Edit RadTreeNode DataBindings. The "RadTreeNodeBinding Collection Editor" dialog appears.
  8. 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.)
  9. Set the properties for each member. When ready, click OK.
  10. Important notes about DataBindings properties

    Depth
    Gets or sets the treeview 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 RadTreeNode objects to which the RadTreeNodeBinding 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 tree nodes will take its value from the Text column in the database. Alternatively, if you set Text="Text", all your tree nodes 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 tree node. 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 tree node binding that specifies both a 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 <Node> elements that appear at different levels within an XML file. The following RadTreeNodeBinding declarations show how to specify tree node bindings that apply to identical data members at different treeview depths:

    If a tree node binding is defined without a depth and a data member, the tree node binding is applied to all tree nodes within the treeview. This is commonly used when all data items have the same properties and should be displayed identically, regardless of the treeview depth.

    After the binding criteria are established, you can then bind a property of a RadTreeNode 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 RadTreeNodeBinding objects are defined that conflict with each other, Telerik RadTreeView applies the tree node bindings in the following order of precedence:

    1. The RadTreeNodeBinding object that defines both a depth and a data member.
    2. The RadTreeNodeBinding object that defines only the depth.
    3. The RadTreeNodeBinding object that defines only the data member.
    4. The RadTreeNodeBinding object that defines neither the depth nor the data member.

    For a step-by-step walkthrough of this functionality, see our example scenario.

    See Also