RadTreeView for ASP.NET

Overview and types of data sources Send comments on this topic.
See Also
Data Binding > Overview and types of data sources

Glossary Item Box

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:

  1. Set Text, Value or NavigateUrl properties using:
  2. DataTextField - Gets or sets the field of the data source that provides the Text of the treeview items.
  3. DataNavigateUrlField - Gets or sets the field of the data source that provides the NavigateUrl of the treeview items.
  4. DataValueField  - Gets or sets the field of the data source that provides the Value of the treeview items
  5. 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
  6. Establish hierarchy through ID to ParentID relationship using:
  7. DataFieldID - The name of the DataColumn holding the ID value.
  8. DataFieldParentID - The name of the DataColumn holding the ParentID value. The id of the root nodes should be null.
  9.  

    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

    1. Data Sources from which Telerik RadTreeView will automatically create treeview item hierarchy:
      • XmlDataSource
      • SiteMapDataSource
    2. Data Sources which require the ID to ParentID relationship to establish hierarchy:
      • DataTable, DataSet, DataView
      • SqlDataSource
      • AccessDataSource
    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