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 Q2 2011 released 07/12/2011
select

Grid / Client Binding

RadGrid bound to live data:

Stock TickerChangeDaily RangeDailyMinRangeDailyMaxRangeLast Updated
     -     
     -     
     -     
     -     
     -     
     -     
     -     
     -     
     -     
     -     
     -     

  • The example demonstrates how to use RadGrid client-side data-binding to visualize live data using web service. The grid is updated after interval of 1 second passes (specified in the pageLoad handler of the page). This results in simultaneous and seamless pure client-side end-user experience.

    Below is the signature of the web service used in the demo:

    <%@ WebService Language="C#" CodeBehind="~/App_Code/Grid/QuoteWebService.cs" Class="QuoteWebService" %>

    If you would like to familiarize with the QuoteWebService code-behind and its GetListOfStockQuotes method, it is located under the App_Code/Grid/QuoteWebService.cs class of the RadControls for ASP.NET AJAX installation.

Source Code

C# VB.NET
Show code in new window Demo isolation steps
  • <%@ Page Language="VB" AutoEventWireup="false" CodeFile="DefaultVB.aspx.vb" Inherits="Telerik.GridExamplesVBNET.Client.LiveData.DefaultVB" %>

    <%@ 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="Headtag1"></telerik:HeadTag>
        <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">

            <script type="text/javascript">
            //<![CDATA[
                function pageLoad(sender, args)
                {
                    setInterval(getData, 1000);
                }
                function getData()
                {
                    QuoteWebService.GetListOfStockQuotes(updateGrid);
                }

                function updateGrid(result)
                {
                    var tableView = $find("<%= RadGrid1.ClientID %>").get_masterTableView();
                    tableView.set_dataSource(result);
                    tableView.dataBind();
                }
                
                function OnRowDataBound(sender, args)
                {
                    var spanControl = args.get_item().get_cell("Change").getElementsByTagName('span')[0];
                    var image = args.get_item().get_cell("Change").getElementsByTagName('img')[0];
                    if(args.get_dataItem().Change > 0)
                    {
                        image.style.display = "";
                        image.src = "Images/up.gif";
                        spanControl.style.color = "green";
                    }
                    else if(args.get_dataItem().Change < 0)
                    {
                        image.style.display = "";
                        image.src = "Images/down.gif";
                        spanControl.style.color = "red";
                    }
                    else
                    {
                        image.style.display = "none";
                        spanControl.style.color = "";
                    }
                }
                //]]>
            </script>

        </telerik:RadCodeBlock>
    </head>
    <body class="BODY">
        <form runat="server" id="mainForm" method="post">
            <telerik:Header runat="server" ID="Header1" NavigationLanguage="VB"></telerik:Header>
            <telerik:RadScriptManager ID="RadScriptManager" runat="server">
                <Services>
                    <asp:ServiceReference Path="~/Grid/Examples/Client/LiveData/QuoteWebService.asmx" />
                </Services>
            </telerik:RadScriptManager>
            <!-- content start -->
            <h3 class="qsfSubtitle">
                RadGrid bound to live data:</h3>
            <telerik:RadGrid ID="RadGrid1" AutoGenerateColumns="false" runat="server">
                <MasterTableView TableLayout="Fixed">
                    <Columns>
                        <telerik:GridHyperLinkColumn DataTextField="StockTicker" DataNavigateUrlFields="StockTicker"
                            UniqueName="StockTicker" HeaderText="Stock Ticker" DataNavigateUrlFormatString="http://finance.yahoo.com/q?s={0}&amp;d=t" />
                        <telerik:GridTemplateColumn UniqueName="Change" HeaderText="Change" DataField="Change">
                            <ItemTemplate>
                                <asp:Image ID="DirectionImage" runat="server" AlternateText="up" Style="display:none"/>&nbsp;
                                <asp:Label ID="Change" runat="server" Style="font-weight: bold;" />
                            </ItemTemplate>
                            <ItemStyle Width="150px" />
                        </telerik:GridTemplateColumn>
                        <telerik:GridTemplateColumn UniqueName="DailyRange" HeaderText="Daily Range" DataField="DailyRange">
                            <ItemTemplate>
                                <asp:Label ID="DailyMinRange" runat="server" />&nbsp;-&nbsp;
                                <asp:Label ID="DailyMaxRange" runat="server" />
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridBoundColumn DataField="DailyMinRange" UniqueName="DailyMinRange" HeaderText="DailyMinRange">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="DailyMaxRange" UniqueName="DailyMaxRange" HeaderText="DailyMaxRange">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="LastUpdated" UniqueName="LastUpdated" HeaderText="Last Updated"
                            DataFormatString="{0:dd/MM/yyyy' 'HH':'mm':'ss}" />
                    </Columns>
                </MasterTableView>
                <ClientSettings>
                    <ClientEvents OnCommand="function(){}" OnRowDataBound="OnRowDataBound"/>
                </ClientSettings>
            </telerik:RadGrid>
            <!-- content end -->
            <telerik:Footer runat="server" ID="Footer1"></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-2024 © Telerik. All right reserved
Telerik Inc, 201 Jones Rd, Waltham, MA 02451