New to Telerik UI for ASP.NET AJAX? Download free 30-day trial

Declarative DataSources

SiteMapDataSource

  • All
    • Products
      • UI for ASP.NET AJAX
      • UI for WinForms
      • UI for WPF
      • UI for Silverlight
      • Reporting
      • Data Access
      • Sitefinity ASP.NET CMS
      • Test Studio
    • Consulting
      • On-site Training
      • Consulting Express
      • Open Classes Training
      • Online Training
      • Project Consulting
      • Telerik Webinars
    • Purchase
      • Buy Now
      • Renewals & Upgrades
      • License Agreement
      • FAQ
      • Purchase Orders
      • Contact Sales
    • Support
      • Support by Product
      • Documentation
      • Demos
      • Knowledge Base
      • Telerik Trainer
      • Videos
      • Skins
    • Community
      • Forums
      • Blogs
      • Events
      • Code Library
      • Learning Resources
      • Announcements
      • Free Products
    • Company
      • About Telerik
      • Press Center
      • Careers
      • Contact Us

ObjectDataSource

  • UI for ASP.NET Ajax
    • Grid
    • Scheduler
    • Editor
  • UI for Silverlight
    • Grid
    • Menu
    • Editor

SqlDataSource

  • Fuller
    • Davolio
    • Leverling
    • Peacock
    • Buchanan
      • Suyama
      • King
      • Dodsworth
    • Callahan
RadTreeView supports binding to various types of data sources, including declarative datasources.

Some of the declarative data sources are inherently hierarchical. These include SiteMapDataSource and XmlDataSource. When data-bound to these types of data sources, RadTreeView automatically creates the node hierarchy. There is no need to use the DataFieldID and DataFieldParentID properties.

The AccessDataSource is a table-based DataSource component. It can be used to bind the treeview declaratively at design time. As with binding to a DataSet, DataTable, or DataView, you can use the ID-ParentID relation to establish a hierarchy among the nodes.

RadTreeView supports binding to an ObjectDataSource as well. In addition to the standard Node properties (Text, Value, Navigate Url, etc.) that can be bound to the underlying business objects, the DataFieldID and DataFieldParentID properties can be specified, too. In this way, RadTreeView can create a hierarchy of Nodes.

Still, the business objects should provide the data needed for the RadTreeView to build the hierarchy. If the ParentID property of the business objects are of nullable or reference type, then null values denote root Nodes. In case, the ParentID property is of value type (Integer, Guid, etc.), '0'/'Guid.Empty' values denote the root Nodes.

For more details on the aforementioned algorithm, please read the documentation topic - Binding to Array, ArrayList and Generic List.

  • DefaultCS.aspx
  • DefaultCS.aspx.cs
    • DefaultCS.aspx.cs
    • SiteDataItem.cs
  • styles.css
<%@ Page Language="c#" AutoEventWireup="true" CodeFile="DefaultCS.aspx.cs" 
    Inherits="TreeView.Examples.Programming.DeclarativeDatasources.DefaultCS" %>

<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head runat="server">
    <title>Telerik ASP.NET Example</title>
    <link href="styles.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
    <telerik:RadSkinManager ID="RadSkinManager1" runat="server" ShowChooser="true" />
    <div class="demo-containers">
        <div class="demo-container size-thin">
            <h2>SiteMapDataSource
            </h2>
            <telerik:RadTreeView RenderMode="Lightweight" ID="RadTreeView1" runat="server"  Width="280px" Height="250px"
                DataSourceID="SiteMapDataSource1" OnNodeDataBound="RadTreeView1_NodeDataBound">
                <DataBindings>
                    <telerik:RadTreeNodeBinding Expanded="true"></telerik:RadTreeNodeBinding>
                </DataBindings>
            </telerik:RadTreeView>
        </div>
        <div class="demo-container size-thin">
            <h2>ObjectDataSource</h2>

            <telerik:RadTreeView RenderMode="Lightweight" ID="RadTreeView2" runat="server"  Width="280px" Height="250px"
                DataSourceID="ObjectDataSource1" DataFieldID="ID" DataFieldParentID="ParentID"
                DataTextField="Text">
                <DataBindings>
                    <telerik:RadTreeNodeBinding Expanded="true"></telerik:RadTreeNodeBinding>
                </DataBindings>
            </telerik:RadTreeView>
        </div>

        <div class="demo-container size-thin">
            <h2>SqlDataSource</h2>

            <telerik:RadTreeView RenderMode="Lightweight" ID="RadTreeView3" runat="server"  Width="280px" Height="250px"
                DataFieldID="EmployeeID" DataFieldParentID="ReportsTo" DataTextField="LastName"
                DataSourceID="SqlDataSource1">
                <DataBindings>
                    <telerik:RadTreeNodeBinding Expanded="true"></telerik:RadTreeNodeBinding>
                </DataBindings>
            </telerik:RadTreeView>

        </div>
    </div>
    <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server"></asp:SiteMapDataSource>
    <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetSiteData"
        TypeName="Telerik.Web.Examples.SiteDataItem"></asp:ObjectDataSource>
    <asp:SqlDataSource runat="server" ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
        SelectCommand="SELECT * From Employees"></asp:SqlDataSource>
    </form>
</body>
</html>

Support & Learning Resources

Find Assistance