RadGrid for ASP.NET AJAX

RadControls for ASP.NET AJAX

This online demo represents 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.

CopyJavaScript
function pageLoad(sender, args) {
  setInterval("QuoteWebService.GetListOfStockQuotes(updateGrid)", 1000);
}
function updateGrid(result) {
  var tableView = $find("<%= RadGrid1.ClientID %>").get_masterTableView();
  tableView.set_dataSource(result); tableView.dataBind();
}

Naturally, you can change the live feed or the custom collection of objects returned by the web service in conjunction with your own preferences and in order to conform to your visualization schema.

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

and the source code of the page holding the grid instance populated through a web service on the client:

CopyASPX
<head runat="server">
  <telerik:HeadTag runat="server" ID="Headtag1">
  </telerik:HeadTag>
  <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
    <script type="text/javascript">   
      function pageLoad(sender, args) {
        setInterval("QuoteWebService.GetListOfStockQuotes(updateGrid)", 1000);
      }
      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";
        }
        elseimage.style.display = "none";
          spanControl.style.color = "";
        }
      }                                                                                                                          
    </scripttelerik:RadCodeBlockhead>
<body class="BODY">
  <form runat="server" id="mainForm" method="post" style="width: 100%;">
  <telerik:RadScriptManager ID="RadScriptManager" runat="server">
    <Services>
      <asp:ServiceReference Path="~/Grid/Examples/Client/LiveData/QuoteWebService.asmx" />
    </Services>
  </telerik:RadScriptManager>
  <!-- content start -->
  <h3>
    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}&d=t" />
        <telerik:GridTemplateColumn UniqueName="Change" HeaderText="Change" DataField="Change">
          <ItemTemplate>
            <asp:Image ID="DirectionImage" runat="server" AlternateText="up" Style="display: none" /> 
            <asp:Label ID="Change" runat="server" Style="font-weight: bold;" />
          </ItemTemplate>
          <ItemStyle Width="150px" />
        </telerik:GridTemplateColumn>
        <telerik:GridTemplateColumn UniqueName="DailyRange" DataField="DailyRange" HeaderText="Daily Range">
          <ItemTemplate>
            <asp:Label ID="DailyMinRange" runat="server" /> - 
            <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>
  </form>
</body>