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.
select

Grid / Master/Details Client-Side Binding


  • This example demonstrates master/details RadGrid with client-side data-binding to WCF Web Service. Both RadGrids have enabled paging/sorting/filtering.

    To do this you need to point to an existing web service and method with following signiture:

    [OperationContract]
    public MyData GetCustomerDataAndCount/GetOrdersDataAndCount(int startRowIndex, int maximumRows, string sortExpression, string filterExpression)

    MyData is custom class that holds data returned from the service to client:

    public class MyData
    {
     public int Count { get; set; }
     public IList Data { get; set; }
    }

Source Code

C# VB.NET
Show code in new window Demo isolation steps
  • <%@ Page Language="C#" %>

    <%@ Register TagPrefix="qsf" Namespace="Telerik.QuickStart" %>
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <%@ Register TagPrefix="qsf" TagName="Header" Src="~/Common/Header.ascx" %>
    <%@ Register TagPrefix="qsf" TagName="HeadTag" Src="~/Common/HeadTag.ascx" %>
    <%@ Register TagPrefix="qsf" TagName="Footer" Src="~/Common/Footer.ascx" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <qsf:HeadTag ID="Headtag1" runat="server"></qsf:HeadTag>
        <telerik:RadCodeBlock runat="server" ID="RadCodeBlock1">
        <script type="text/javascript">
            var customerID = "";
            function RadGrid1_RowSelected(sender, args)
            {
                customerID = args.get_tableView().extractKeysFromItem(args.get_gridDataItem().get_element())["CustomerID"];
                $find("<%=RadGrid2.ClientID %>").get_masterTableView().filter("CustomerID", customerID, "EqualTo");
            }

            function RadGrid1_DataBound(sender, args)
            {
                var tableView = sender.get_masterTableView();
                var dataItems = tableView.get_dataItems();
                if (dataItems.length > 0)
                {
                    tableView.selectItem(0);
                }
            }

            function RadGrid2_DataBinding(sender, args)
            {
                if (customerID === "")
                {
                    args.set_cancel(true);
                }
            }
        </script>
        </telerik:RadCodeBlock>
    </head>
    <body class="BODY">
        <form id="form1" runat="server">
        <telerik:RadScriptManager runat="server" ID="RadScriptManager1">
        </telerik:RadScriptManager>
        <div>
            <qsf:Header ID="Header1" runat="server" NavigationLanguage="C#"></qsf:Header>
            
            <br />
            <br />
            <strong>Customers:</strong>
            
            <telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="true" AllowSorting="True"
                AllowFilteringByColumn="true" GridLines="None" PageSize="5">
                <MasterTableView ClientDataKeyNames="CustomerID" AllowMultiColumnSorting="true">
                    <PagerStyle Mode="NumericPages" />
                    <Columns>
                        <telerik:GridBoundColumn DataField="CustomerID" HeaderText="CustomerID" />
                        <telerik:GridBoundColumn DataField="CompanyName" HeaderText="CompanyName" />
                        <telerik:GridBoundColumn DataField="ContactName" HeaderText="ContactName" />
                        <telerik:GridBoundColumn DataField="ContactTitle" HeaderText="ContactTitle" />
                        <telerik:GridBoundColumn DataField="Country" HeaderText="Country" />
                        <telerik:GridBoundColumn DataField="City" HeaderText="City" />
                    </Columns>
                </MasterTableView>
                <ClientSettings>
                    <DataBinding Location="GridMasterDetailsService.svc" FilterParameterType="Linq"
                        SelectMethod="GetCustomerDataAndCount" SortParameterType="Linq" >
                    </DataBinding>
                    <ClientEvents OnRowSelected="RadGrid1_RowSelected" OnDataBound="RadGrid1_DataBound"/>
                    <Selecting AllowRowSelect="true" />
                </ClientSettings>
            </telerik:RadGrid>
            
            <br />
            <strong>Orders:</strong>
            
            <telerik:RadGrid ID="RadGrid2" runat="server" AllowPaging="true" AllowSorting="True"
                AllowFilteringByColumn="true" GridLines="None" PageSize="5">
                <MasterTableView AllowMultiColumnSorting="true">
                    <PagerStyle Mode="NumericPages" />
                    <Columns>
                        <telerik:GridBoundColumn DataField="CustomerID" HeaderText="CustomerID" Display="false"/>
                        <telerik:GridBoundColumn DataType="System.Int32" DataField="OrderID"
                            HeaderText="OrderID" />
                        <telerik:GridBoundColumn DataType="System.DateTime" DataFormatString="{0:MM/dd/yyyy}"
                            DataField="OrderDate" HeaderText="OrderDate" />
                        <telerik:GridBoundColumn DataType="System.Decimal" DataField="Freight"
                            HeaderText="Freight" />
                        <telerik:GridBoundColumn DataField="ShipName" HeaderText="ShipName" />
                    </Columns>
                </MasterTableView>
                <ClientSettings>
                    <DataBinding Location="GridMasterDetailsService.svc" FilterParameterType="Linq"
                        SelectMethod="GetOrdersDataAndCount" SortParameterType="Linq">
                    </DataBinding>
                    <ClientEvents OnDataBinding="RadGrid2_DataBinding" />
                </ClientSettings>
            </telerik:RadGrid>
             
            <qsf:Footer ID="Footer1" runat="server"></qsf:Footer>
        </div>
        </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