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

Various data sources

Binding to List of custom objects with Nullable properties

TextIDPID
Item 22 
Item 55 

Binding to Generic list

TitleDescription
Telerik UI for ASP.NET AjaxTelerik UI for ASP.NET AJAX includes more than 80 controls with proven reliability that help you build high-quality, professional line of business web applications.
Telerik UI for SilverlightTelerik controls are built on Microsoft Silverlight and include 40+ UI controls for building rich line-of-business Silverlight applications.

Binding to DataReader

EmployeeIDLastNameFirstNameTitleTitleOfCourtesyReportsTo
2FullerAndrewVice President, SalesDr. 

Binding to SiteMapDataSource

TitleHasChildNodesKey
1
Page size:
AllTruef8dde4ea-fd0d-4e54-b3d2-b238630abff6

You can use a wide variety of data-sources for RadTreeList structure generation. A requirement is that these custom objects implement the ITypedList/IEnumarable/ICustomTypeDescriptor interfaces and representing self-hierarchical data. Remember to set the DataKeyNames and ParentDataKeyNames properties of the RadTreeList controls.

Note that the type of the fields used for DataKeyNames and ParentDatakeyNames should be the same.

The code under the ASPX/C#/VB.NET tabs demonstrates how to:
  • use List of custom objects with Nullable properties
  • bind RadTreeList to list of custom objects (Generic list)
  • bind RadTreeList to a DataReader
  • bind RadTreeList to a SiteMapDataSource

When binding to SiteMapDataSource control you can avoid setting the DataKeyNames and the ParentDataKeyNames because they are resolved internally due to the nature of this datasource type.

Related Resources

Binding RadTreeList to various data sources

  • DefaultCS.aspx
  • DefaultCS.aspx.cs
<%@ Page Language="c#" Inherits="Telerik.TreeListExamplesCSharp.DataBinding.VariousDataSources.DefaultCS"CodeFile="DefaultCS.aspx.cs"  %>

<%@ 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>
    <style type="text/css">
        .RadTreeList td {
            vertical-align: top;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
    <telerik:RadSkinManager ID="RadSkinManager1" runat="server" ShowChooser="true" />
    <div class="demo-container no-bg">
        <h4 class="qsfSubtitle">Binding to List of custom objects with <b>Nullable</b> properties</h4>
        <telerik:RadAjaxPanel ID="RadAjaxPanel1" LoadingPanelID="RadAjaxLoadingPanel1" runat="server">
            <telerik:RadTreeList RenderMode="Lightweight" runat="server" ID="RadTreeList1" DataKeyNames="ID" ParentDataKeyNames="PID"
                OnNeedDataSource="RadTreeList1_NeedDataSource" AutoGenerateColumns="false">
                <Columns>
                    <telerik:TreeListBoundColumn DataField="Text" HeaderText="Text" UniqueName="Text">
                    </telerik:TreeListBoundColumn>
                    <telerik:TreeListBoundColumn DataField="ID" HeaderText="ID" UniqueName="ID">
                    </telerik:TreeListBoundColumn>
                    <telerik:TreeListBoundColumn DataField="PID" HeaderText="PID" UniqueName="PID">
                    </telerik:TreeListBoundColumn>
                </Columns>
            </telerik:RadTreeList>
        </telerik:RadAjaxPanel>
        <br />
        <h4 class="qsfSubtitle">Binding to Generic list</h4>
        <telerik:RadAjaxPanel ID="RadAjaxPanel2" LoadingPanelID="RadAjaxLoadingPanel1" runat="server">
            <telerik:RadTreeList RenderMode="Lightweight" runat="server" ID="RadTreeList2" DataKeyNames="ID" ParentDataKeyNames="ParentID"
                OnNeedDataSource="RadTreeList2_NeedDataSource" AutoGenerateColumns="false">
                <Columns>
                    <telerik:TreeListBoundColumn DataField="Title" HeaderText="Title" UniqueName="Title">
                        <HeaderStyle Width="200px"></HeaderStyle>
                    </telerik:TreeListBoundColumn>
                    <telerik:TreeListBoundColumn DataField="Description" HeaderText="Description" UniqueName="Description">
                    </telerik:TreeListBoundColumn>
                </Columns>
            </telerik:RadTreeList>
        </telerik:RadAjaxPanel>
        <br />
        <h4 class="qsfSubtitle">Binding to DataReader</h4>
        <telerik:RadAjaxPanel ID="RadAjaxPanel3" LoadingPanelID="RadAjaxLoadingPanel1" runat="server">
            <telerik:RadTreeList RenderMode="Lightweight" runat="server" ID="RadTreeList3" DataKeyNames="EmployeeID" ParentDataKeyNames="ReportsTo"
                OnNeedDataSource="RadTreeList3_NeedDataSource" OnDataBound="RadTreeList3_DataBound">
            </telerik:RadTreeList>
        </telerik:RadAjaxPanel>
        <br />
        <h4 class="qsfSubtitle">Binding to SiteMapDataSource</h4>
        <telerik:RadAjaxPanel ID="RadAjaxPanel4" LoadingPanelID="RadAjaxLoadingPanel1" runat="server">
            <telerik:RadTreeList RenderMode="Lightweight" ID="RadTreeList4" runat="server" DataSourceID="SiteMapDataSource1"
                AutoGenerateColumns="false" AllowPaging="true" PageSize="10">
                <Columns>
                    <telerik:TreeListBoundColumn DataField="Title" HeaderText="Title"></telerik:TreeListBoundColumn>
                    <telerik:TreeListBoundColumn DataField="HasChildNodes" HeaderText="HasChildNodes"></telerik:TreeListBoundColumn>
                    <telerik:TreeListBoundColumn DataField="Key" HeaderText="Key"></telerik:TreeListBoundColumn>
                </Columns>
            </telerik:RadTreeList>
            <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
        </telerik:RadAjaxPanel>
        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server">
        </telerik:RadAjaxLoadingPanel>
    </div>
    </form>
</body>
</html>

Support & Learning Resources

Find Assistance