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
TRADHTradição HipermercadosAnabela DominguesSales RepresentativeAv. Inês de Castro, 414Sao PauloSP05634-030Brazil(11) 555-2167(11) 555-2168
TRAIHTrail's Head Gourmet ProvisionersHelvetius NagySales Associate722 DaVinci Blvd.KirklandWA98034USA(206) 555-8257(206) 555-2174
VAFFEVaffeljernetPalle IbsenSales ManagerSmagsloget 45Århus 8200Denmark86 21 32 4386 22 33 44
VICTEVictuailles en stockMary SaveleySales Agent2, rue du CommerceLyon 69004France78.32.54.8678.32.54.87
VINETVins et alcools ChevalierPaul HenriotAccounting Manager59 rue de l'AbbayeReims 51100France26.47.15.1026.47.15.11
WANDKDie Wandernde KuhRita MüllerSales RepresentativeAdenauerallee 900Stuttgart 70563Germany0711-0203610711-035428
WARTHWartian HerkkuPirkko KoskitaloAccounting ManagerTorikatu 38Oulu 90110Finland981-443655981-443655
WELLIWellington ImportadoraPaula ParenteSales ManagerRua do Mercado, 12ResendeSP08737-363Brazil(14) 555-8122 
WHITCWhite Clover MarketsKarl JablonskiOwner305 - 14th Ave. S. Suite 3BSeattleWA98128USA(206) 555-4112(206) 555-4115
WILMKWilman KalaMatti KarttunenOwner/Marketing AssistantKeskuskatu 45Helsinki 21240Finland90-224 885890-224 8858

Advanced Data Binding (using the NeedDataSource event):

Customer IDCompany NameContact NameContact TitleAddressCityRegionPostal CodeCountryPhoneFaxBool
Page size:
 91 items in 10 pages
QUEDEQue DelíciaBernardo BatistaAccounting ManagerRua da Panificadora, 12Rio de JaneiroRJ02389-673Brazil(21) 555-4252(21) 555-4545
QUEENQueen CozinhaLúcia CarvalhoMarketing AssistantAlameda dos Canàrios, 891Sao PauloSP05487-020Brazil(11) 555-1189 
QUICKQUICK-StopHorst KlossAccounting ManagerTaucherstraße 10Cunewalde 01307Germany0372-035188 
RANCHRancho grandeSergio GutiérrezSales RepresentativeAv. del Libertador 900Buenos Aires 1010Argentina(1) 123-5555(1) 123-5556
RATTCRattlesnake Canyon GroceryPaula WilsonAssistant Sales Representative2817 Milton Dr.AlbuquerqueNM87110USA(505) 555-5939(505) 555-3620
REGGCReggiani CaseificiMaurizio MoroniSales AssociateStrada Provinciale 124Reggio Emilia 42100Italy0522-5567210522-556722
RICARRicardo AdocicadosJanete LimeiraAssistant Sales AgentAv. Copacabana, 267Rio de JaneiroRJ02389-890Brazil(21) 555-3412 
RICSURichter SupermarktMichael HolzSales ManagerGrenzacherweg 237Genève 1203Switzerland0897-034214 
ROMEYRomero y tomilloAlejandra CaminoAccounting ManagerGran Vía, 1Madrid 28001Spain(91) 745 6200(91) 745 6210
SANTGSanté GourmetJonas BergulfsenOwnerErling Skakkes gate 78Stavern 4110Norway07-98 92 3507-98 92 47
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