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

Grid / Various DataSources


Binding RadGrid to:
ArrayList:
Drag a column header and drop it here to group by that column
Item
string1
string2
string3
List of custom objects,
with .NET 2 Nullable properties:
Drag a column header and drop it here to group by that column
AB
Item 00
Item 10
Item 21
Item 31
Item 4 
Binding to Sub objects:
Drag a column header and drop it here to group by that column
Inner1.TestPropInner1.Inner2.TestPropInner1.Inner2.Inner1.TestPropTest Prop
1Inner11Inner1Inner21Inner1Inner2Inner11
2Inner12Inner1Inner22Inner1Inner2Inner12
3Inner13Inner1Inner23Inner1Inner2Inner13
4Inner14Inner1Inner24Inner1Inner2Inner14
1Inner11Inner1Inner21Inner1Inner2Inner11
Binding to DataReader:
Drag a column header and drop it here to group by that column
Customer IDCompany NameContact NameContact TitleAddressPostal Code
ALFKIAlfreds FutterkisteMaria AndersSales RepresentativeObere Str. 5712209
ANATRAna Trujillo Emparedados y heladosAna TrujilloOwnerAvda. de la Constitución 222205021
ANTONAntonio Moreno TaqueríaAntonio MorenoOwnerMataderos 231205023
AROUTAround the HornThomas HardySales Representative120 Hanover Sq.WA1 1DP
BERGSBerglunds snabbköpChristina BerglundOrder AdministratorBerguvsvägen 8S-958 22


  • You can use a wide variety of data-sources for grid structure generation (the only requirement is that these custom objects implement the ITypedList/IEnumarable/ICustomTypeDescriptor interfaces). The code under the ASPX/C#/VB.NET tabs demonstrates how to:
    • useArrayList object for Telerik RadGrid structure generation
    • bind the grid to list of custom objects with Nullable properties (.NET 2.0 feature)
    • bind the grid to subobjects by the intuitive and simple dot(.) syntax (specified through the DataField property of declaratively bound columns), for example:
      <telerik:GridBoundColumn DataField="Inner1.Inner2.TestProp" HeaderText="Inner1.Inner2.TestProp">
    • bind the grid to DataReader

Source Code

C# VB.NET
Show code in new window Demo isolation steps
  • <%@ Page Language="c#" Inherits="Telerik.GridExamplesCSharp.Programming.Binding.DefaultCS"
        CodeFile="DefaultCS.aspx.cs" %>

    <%@ Register TagPrefix="telerik" Namespace="Telerik.QuickStart" %>
    <%@ Register TagPrefix="telerik" TagName="Header" Src="~/Common/Header.ascx" %>
    <%@ Register TagPrefix="telerik" TagName="HeadTag" Src="~/Common/HeadTag.ascx" %>
    <%@ Register TagPrefix="telerik" TagName="Footer" Src="~/Common/Footer.ascx" %>
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/tr/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <telerik:HeadTag runat="server" ID="Headtag2"></telerik:HeadTag>
        <!-- custom head section -->
        <link href="../../Styles/default/Styles.css" rel="stylesheet" type="text/css" />
        <style type="text/css">
                    .RadGrid th { font: bold 11px tahoma; white-space:nowrap; }
                </style>
        <!-- end of custom head section -->
    </head>
    <body class="BODY">
        <form runat="server" id="mainForm" method="post">
            <telerik:Header runat="server" ID="Header1" NavigationLanguage="CS"></telerik:Header>
            <telerik:RadScriptManager ID="RadScriptManager1" runat="server" />
            <!-- content start -->
            <br />
            <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
                <AjaxSettings>
                    <telerik:AjaxSetting AjaxControlID="RadGrid1">
                        <UpdatedControls>
                            <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                        </UpdatedControls>
                    </telerik:AjaxSetting>
                    <telerik:AjaxSetting AjaxControlID="RadGrid2">
                        <UpdatedControls>
                            <telerik:AjaxUpdatedControl ControlID="RadGrid2" />
                        </UpdatedControls>
                    </telerik:AjaxSetting>
                    <telerik:AjaxSetting AjaxControlID="RadGrid3">
                        <UpdatedControls>
                            <telerik:AjaxUpdatedControl ControlID="RadGrid3" />
                        </UpdatedControls>
                    </telerik:AjaxSetting>
                    <telerik:AjaxSetting AjaxControlID="RadGrid4">
                        <UpdatedControls>
                            <telerik:AjaxUpdatedControl ControlID="RadGrid4" />
                        </UpdatedControls>
                    </telerik:AjaxSetting>
                </AjaxSettings>
            </telerik:RadAjaxManager>
            <table id="Table1" cellspacing="1" cellpadding="11" border="0" rules="rows" style="width: 95%;
                borders-collapse: Collapse">
                <tr>
                    <td style="width: 145px">
                        <b>Binding RadGrid to:</b></td>
                    <td>
                    </td>
                </tr>
                <tr>
                    <td valign="top">
                        ArrayList:</td>
                    <td>
                        <telerik:RadGrid ID="RadGrid1" runat="server" GridLines="None"
                         ShowGroupPanel="True" Width="100%" AllowSorting="True" OnNeedDataSource="RadGrid1_NeedDataSource">
                            <MasterTableView />
                              <ClientSettings AllowDragToGroup="True">
                            </ClientSettings>
                        </telerik:RadGrid>
                    </td>
                </tr>
                <tr>
                    <td style="white-space: wrap; width: 177px;">
                        List of custom objects,
                        <br />
                        with .NET 2 <strong>Nullable</strong> properties:</td>
                    <td>
                        <telerik:RadGrid ID="RadGrid2" runat="server" GridLines="None" Width="100%"
                            ShowGroupPanel="True" AllowSorting="True" OnNeedDataSource="RadGrid2_NeedDataSource" ShowStatusBar="true">
                            <ClientSettings AllowDragToGroup="True">
                            </ClientSettings>
                         </telerik:RadGrid>
                    </td>
                </tr>
                <tr>
                    <td style="white-space: nowrap;" valign="top">
                        Binding to Sub objects:
                    </td>
                    <td>
                        <telerik:RadGrid ID="RadGrid3" runat="server" GridLines="None" Width="100%"
                            ShowGroupPanel="True" AllowSorting="True" OnNeedDataSource="RadGrid3_NeedDataSource" ShowStatusBar="true">
                             <ClientSettings AllowDragToGroup="True">
                            </ClientSettings>
                            <MasterTableView RetrieveAllDataFields="false" AutoGenerateColumns="True">
                                <Columns>
                                    <telerik:GridBoundColumn DataField="Inner1.TestProp" HeaderText="Inner1.TestProp">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="Inner1.Inner2.TestProp" HeaderText="Inner1.Inner2.TestProp">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="Inner1.Inner2.Inner1.TestProp" HeaderText="Inner1.Inner2.Inner1.TestProp">
                                    </telerik:GridBoundColumn>
                                </Columns>
                             </MasterTableView>
                        </telerik:RadGrid>
                    </td>
                </tr>
                <tr>
                    <td style="white-space: nowrap;" valign="top">
                        Binding to DataReader:
                    </td>
                    <td>
                        <telerik:RadGrid ID="RadGrid4" runat="server" AutoGenerateColumns="true" ShowStatusBar="true"
                            AllowSorting="true" ShowGroupPanel="true" OnNeedDataSource="RadGrid4_NeedDataSource" OnDataBound="RadGrid4_DataBound">
                            <ClientSettings AllowDragToGroup="True">
                            </ClientSettings>
                        </telerik:RadGrid>
                    </td>
                </tr>
            </table>
            <br />
            <!-- content end -->
            <telerik:Footer runat="server" ID="Footer1" AdditionalCodeViewerFiles="~/Grid/Examples/Styles/default/Styles.css"></telerik: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