<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default"
    Culture="auto" %>

<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<!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">
    <title>Untitled Page</title>
    <style type="text/css">  
   
   


    </style>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager runat="server" ID="Manager1">
        </asp:ScriptManager>
        <telerik:RadScriptBlock runat="server" ID="RadScriptBlock">

            <script type="text/javascript" language="javascript">
            
            var RadGrid;
            function GridCreated(sender, args)
            {
            RadGrid=sender;
            var dataItems = RadGrid.get_masterTableView().get_dataItems();           
            var detailTables = RadGrid.get_detailTables();
            
                for(var i=0; i<RadGrid.get_detailTables().length; i++)
                {
                var temp = RadGrid.get_detailTables()[0].get_dataItems();
                }
            
            }
            
           function rowSelecting(sender, eventArgs) {     
           
          if(eventArgs._domEvent.type=="click")
          {
                 var masterTable = RadGrid.get_masterTableView();  
                 var detailTableView = eventArgs.get_tableView();  
                 
                 //eventArgs.get_gridDataItem().get_nestedViews()
                  if (detailTableView.get_name() == "MasterTable")  //Name of DetailTable  
                 {  
                     var nestedView = eventArgs.get_gridDataItem().get_nestedViews();
                     nestedView[0].selectAllItems();
                 }  
                 
                 else if (detailTableView.get_name() == "detailTableLevel2")  //Name of DetailTable  
                 {  
                     masterTable.selectItem(detailTableView.get_parentRow());  
                     debugger;
                      var nestedView = eventArgs.get_gridDataItem().get_nestedViews();
                     nestedView[0].selectAllItems();
                 }  
                  
                else if (detailTableView.get_name() == "detailTableLevel3")  //Name of DetailTable  
                 {  
                     detailTableView.selectItem(detailTableView.get_parentView().get_parentRow());                      
                 }  
                  
             } 
            } 

          
            </script>

        </telerik:RadScriptBlock>   
           
            
        <telerik:RadGrid runat="server"
         AllowMultiRowEdit="True"
         AllowMultiRowSelection="true" 
         ID="RadGrid1" AllowSorting="True" GridLines="None" 
        AllowFilteringByColumn="True" DataSourceID="AccessDataSource1">  
            <MasterTableView AutoGenerateColumns="False"
             HierarchyLoadMode="Client"
             Name="MasterTable"
             EditMode="InPlace"
             DataKeyNames="OrderID" 
             AllowMultiColumnSorting="True" >             
                <Columns>
                    <telerik:GridBoundColumn DataField="OrderID" DataType="System.Int32" HeaderText="OrderID"
                        ReadOnly="True" SortExpression="OrderID" UniqueName="OrderID">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="CustomerID" HeaderText="CustomerID" SortExpression="CustomerID"
                        UniqueName="CustomerID">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="EmployeeID" DataType="System.Int32" HeaderText="EmployeeID"
                        SortExpression="EmployeeID" UniqueName="EmployeeID">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="OrderDate" DataType="System.DateTime" HeaderText="OrderDate"
                        SortExpression="OrderDate" UniqueName="OrderDate">
                    </telerik:GridBoundColumn>                  
                </Columns>
                
                <DetailTables>
                <telerik:GridTableView HierarchyLoadMode="Client"                 
                 DataSourceID="AccessDataSource1" AutoGenerateColumns="true" Name="detailTableLevel2">                
                <DetailTables>
                <telerik:GridTableView DataSourceID="AccessDataSource1" AutoGenerateColumns="true" Name="detailTableLevel3">
                </telerik:GridTableView>
                </DetailTables>                
                </telerik:GridTableView>                
                </DetailTables>
                
            </MasterTableView>
            <ClientSettings>
            <ClientEvents OnGridCreated="GridCreated" OnRowSelecting="rowSelecting" />
                <Selecting AllowRowSelect="True" />
            </ClientSettings>
        </telerik:RadGrid>
        <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/Nwind.mdb"
            SelectCommand="SELECT TOP 3 [OrderID], [CustomerID], [EmployeeID], [OrderDate], [RequiredDate] FROM [Orders]">
        </asp:AccessDataSource>
     
        <br />
    </form>
</body>
</html>
