Telerik is a leading vendor of ASP.NET AJAX, ASP.NET MVC, Silverlight, WinForms and WPF controls and components, as well as .NET Reporting, .NET ORM , .NET CMS, Code Analysis, Mocking, Team Productivity and Automated Testing Tools. Building on its expertise in interface development and Microsoft technologies, Telerik helps customers build applications with unparalleled richness, responsiveness and interactivity. Telerik products help thousands of companies to be more productive and deliver reliable applications under budget and on time.
Version Q1 2012 released 04/11/2012
select

TreeView / Declarative DataSources

  • XmlDataSource
    • All
      • Products
        • ASP.NET AJAX Controls
        • WinForms Controls
        • WPF Controls
        • Silverlight Controls
        • Telerik Reporting
        • Telerik OpenAccess ORM
        • Sitefinity ASP.NET CMS
        • WebUI 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
    • RadControls for ASP.NET Ajax
      • RadGrid
      • RadScheduler
      • RadEditor
    • RadControls for Silverlight
      • RadGrid
      • RadMenu
      • RadEditor
  • 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.

Source Code

C# VB.NET
Show code in new window Demo isolation steps
  • <%@ Page Language="c#" %>

    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <%@ Register TagPrefix="qsf" TagName="Footer" Src="~/Common/Footer.ascx" %>
    <%@ Register TagPrefix="qsf" TagName="HeadTag" Src="~/Common/HeadTag.ascx" %>
    <%@ Register TagPrefix="qsf" TagName="Header" Src="~/Common/Header.ascx" %>
    <%@ Register TagPrefix="qsf" Namespace="Telerik.QuickStart" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <script runat="server">

        protected void RadTreeView1_NodeDataBound(object sender, RadTreeNodeEventArgs e)
        {
            e.Node.Text = Server.HtmlEncode(e.Node.Text);
        }
    </script>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <qsf:HeadTag runat="server" ID="Headtag1"></qsf:HeadTag>
        <link href="styles.css" rel="stylesheet" type="text/css" />
    </head>
    <body class="BODY">
        <form runat="server" id="mainForm" method="post">
            <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
            <qsf:Header runat="server" ID="Header1" NavigationLanguage="C#"></qsf:Header>
            <ul class="treeview-list" style="margin-left: 100px;">
                <li class="treeview-item" style="border: none">
                    <div class="text">
                        XmlDataSource</div>
                    <telerik:RadTreeView ID="RadTreeView1" runat="server" Width="100%" Height="250px"
                         DataSourceID="SiteMapDataSource1" onnodedatabound="RadTreeView1_NodeDataBound">
                        <DataBindings>
                            <telerik:RadTreeNodeBinding Expanded="true" />
                        </DataBindings>
                    </telerik:RadTreeView>
                </li>
                <li class="treeview-item">
                    <div class="text">
                        ObjectDataSource</div>
                    <telerik:RadTreeView ID="RadTreeView2" runat="server" Width="100%" Height="250px"
                         DataSourceID="ObjectDataSource1" DataFieldID="ID" DataFieldParentID="ParentID"
                        DataTextField="Text">
                        <DataBindings>
                            <telerik:RadTreeNodeBinding Expanded="true" />
                        </DataBindings>
                    </telerik:RadTreeView>
                </li>
                <li class="treeview-item">
                    <div class="text">
                        SqlDataSource</div>
                    <telerik:RadTreeView ID="RadTreeView3" runat="server" Width="100%" Height="250px"
                         DataFieldID="EmployeeID" DataFieldParentID="ReportsTo" DataTextField="LastName"
                        DataSourceID="SqlDataSource1">
                        <DataBindings>
                            <telerik:RadTreeNodeBinding Expanded="true" />
                        </DataBindings>
                    </telerik:RadTreeView>
                </li>
            </ul>
            <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
    <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" />
            <qsf:Footer runat="server" ID="Footer1"></qsf:Footer>
        </form>
    </body>
    </html>

Get more than expected!

Take your time to truly experience the power of RadControls for ASP.NET AJAX with a free 60-day trial backed up by Telerik’s unlimited dedicated support.

Download your RadControls for ASP.NET AJAX trial and jumpstart your development with the available Getting Started resources.

If you have any questions, do not hesitate to contact us at sales@telerik.com.

Copyright 2002-2012 © Telerik. All right reserved
Telerik Inc, 201 Jones Rd, Waltham, MA 02451