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

Simple Vs Advanced Data Binding

Simple Data Binding:

Customer IDCompany NameContact NameContact TitleAddressCityRegionPostal CodeCountryPhoneFaxBool
Page size:
 91 items in 10 pages
GOURLGourmet LanchonetesAndré FonsecaSales AssociateAv. Brasil, 442CampinasSP04876-786Brazil(11) 555-9482 
GREALGreat Lakes Food MarketHoward SnyderMarketing Manager2732 Baker Blvd.EugeneOR97403USA(503) 555-7555 
GROSRGROSELLA-RestauranteManuel PereiraOwner5ª Ave. Los Palos GrandesCaracasDF1081Venezuela(2) 283-2951(2) 283-3397
HANARHanari CarnesMario PontesAccounting ManagerRua do Paço, 67Rio de JaneiroRJ05454-876Brazil(21) 555-0091(21) 555-8765
HILAAHILARION-AbastosCarlos HernándezSales RepresentativeCarrera 22 con Ave. Carlos Soublette #8-35San CristóbalTáchira5022Venezuela(5) 555-1340(5) 555-1948
HUNGCHungry Coyote Import StoreYoshi LatimerSales RepresentativeCity Center Plaza 516 Main St.ElginOR97827USA(503) 555-6874(503) 555-2376
HUNGOHungry Owl All-Night GrocersPatricia McKennaSales Associate8 Johnstown RoadCorkCo. Cork Ireland2967 5422967 3333
ISLATIsland TradingHelen BennettMarketing ManagerGarden House Crowther WayCowesIsle of WightPO31 7PJUK(198) 555-8888 
KOENEKöniglich EssenPhilip CramerSales AssociateMaubelstr. 90Brandenburg 14776Germany0555-09876 
LACORLa corne d'abondanceDaniel ToniniSales Representative67, avenue de l'EuropeVersailles 78000France30.59.84.1030.59.85.11

Advanced Data Binding (using the NeedDataSource event):

Customer IDCompany NameContact NameContact TitleAddressCityRegionPostal CodeCountryPhoneFaxBool
Page size:
 91 items in 10 pages
LAMAILa maison d'AsieAnnette RouletSales Manager1 rue Alsace-LorraineToulouse 31000France61.77.61.1061.77.61.11
LAUGBLaughing Bacchus Wine CellarsYoshi TannamuriMarketing Assistant1900 Oak St.VancouverBCV3F 2K1Canada(604) 555-3392(604) 555-7293
LAZYKLazy K Kountry StoreJohn SteelMarketing Manager12 Orchestra TerraceWalla WallaWA99362USA(509) 555-7969(509) 555-6221
LEHMSLehmanns MarktstandRenate MessnerSales RepresentativeMagazinweg 7Frankfurt a.M. 60528Germany069-0245984069-0245874
LETSSLet's Stop N ShopJaime YorresOwner87 Polk St. Suite 5San FranciscoCA94117USA(415) 555-5938 
LILASLILA-SupermercadoCarlos GonzálezAccounting ManagerCarrera 52 con Ave. Bolívar #65-98 Llano LargoBarquisimetoLara3508Venezuela(9) 331-6954(9) 331-7256
LINODLINO-DelicatesesFelipe IzquierdoOwnerAve. 5 de Mayo PorlamarI. de MargaritaNueva Esparta4980Venezuela(8) 34-56-12(8) 34-93-93
LONEPLonesome Pine RestaurantFran WilsonSales Manager89 Chiaroscuro Rd.PortlandOR97219USA(503) 555-9573(503) 555-9646
MAGAAMagazzini Alimentari RiunitiGiovanni RovelliMarketing ManagerVia Ludovico il Moro 22Bergamo 24100Italy035-640230035-640231
MAISDMaison DeweyCatherine DeweySales AgentRue Joseph-Bens 532Bruxelles B-1180Belgium(02) 201 24 67(02) 201 24 68
Simple Data-binding

RadGrid's simple data-binding through the DataBind() method can be used in simple scenarios which does not require complex operations like insert/delete/update, grouping, hierarchy relations, etc. To use Telerik's ASP.NET DataGrid with simple data binding you should:

  • Set the DataSource property. This property points the database which will be used as a source for your grid instance.
  • Call the DataBind() method when appropriate.

The correct approach when using simple data-binding is to call the DataBind() method on the first page load when !Page.IsPostBack and after handling some event (sort event for example). Keep in mind that if you choose simple data-binding, you will need to assign data-source and rebind the grid after each operation (paging, sorting, editing, etc.) - this copies exactly MS DataGrid behavior.

Advanced Data-binding(using the NeedDataSource event)

The key to the advanced data binding of Telerik RadGrid is handling correctly the NeedDataSource event. That's why we chose this exact name. 'Need' in this case actually means that if at an exact moment the data-source property does not point to a valid data-source object, the grid will not behave correctly.

This event fires in the following cases:

  • Right after OnLoad, Telerik RadGrid checks the viewstate for stored grid-related information. If such information is missing (when the page loads for the first time), the NeedDataSource event is fired. This also means that if the EnableViewState property of the grid  has been set to false, the grid will bind each time the page loads (not only the first time)
  • After automatic sorting
  • When paging event occurs
  • When Edit command is fired
  • Right after Update/Delete/Insert command event handlers finish execution. You can cancel these operations handling the ItemCommand event and assigning false value to the Canceled property of the e event argument
  • When grouping/ungrouping columns - right after the RadGrid.GroupsChanging event is raised.
  • When resorting a group
  • When filtering column values
  • When a call to the Rebind() grid method takes place
  • Prior to any detail table binding
  • In some other custom cases.

The advantages of using this event are that the developer does not need to write any code handling the logic about when and how the data-binding should be processed. It is still the developer's responsibility to construct properly a data source object and assign it to the RadGrid's DataSource property.

In the code of the NeedDataSource handler you should prepare the data source (list of objects) for Telerik RadGrid and assign it to the grid's DataSource property.

Note: You should never call the DataBind() method from inside the NeedDataSource handler or mix simple data-binding mode with advanced data-binding
  • DefaultVB.aspx
  • DefaultVB.aspx.vb
<%@ Page Language="vb" AutoEventWireup="false" Inherits="Telerik.GridExamplesVBNET.Programming.SimpleBinding.DefaultVB"CodeFile="DefaultVB.aspx.vb"  %>

<%@ 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>
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
    <telerik:RadSkinManager ID="RadSkinManager1" runat="server" ShowChooser="true" />
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadGrid1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1"></telerik:AjaxUpdatedControl>
                </UpdatedControls>
            </telerik:AjaxSetting>
            <telerik:AjaxSetting AjaxControlID="RadGrid2">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid2"></telerik:AjaxUpdatedControl>
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <div class="demo-container no-bg">
        <h2>Simple Data Binding:</h2>
        <telerik:RadGrid RenderMode="Lightweight" runat="server" ID="RadGrid1" AllowPaging="True" AllowSorting="true"
            OnSortCommand="RadGrid1_SortCommand" OnPageIndexChanged="RadGrid1_PageIndexChanged" OnPageSizeChanged="RadGrid1_PageSizeChanged">
        </telerik:RadGrid>
        <br />
        <h2>Advanced Data Binding (using the NeedDataSource event):</h2>
        <telerik:RadGrid RenderMode="Lightweight" runat="server" ID="RadGrid2" AllowPaging="True" AllowSorting="true"
            OnNeedDataSource="RadGrid2_NeedDataSource">
        </telerik:RadGrid>
    </div>
    </form>
</body>
</html>

Support & Learning Resources

Find Assistance