<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="WebApplication2._Default" %>
<%--<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI, Version=2017.1.228.45, Culture=neutral, PublicKeyToken=121fae78165ba3d4" %>--%>

<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">

    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadGrid1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1"></telerik:AjaxUpdatedControl>
                </UpdatedControls>
            </telerik:AjaxSetting>
            <telerik:AjaxSetting AjaxControlID="lbPostback">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1"></telerik:AjaxUpdatedControl>
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <!-- Client Scripts-->
        <script type="text/javascript">

            function findItemByKey(key, collection, value, isOmission) {
                for (var i = 0; i < collection.length; i++) {
                    if ((collection[i][key] == value) == !isOmission) {
                        return collection[i];
                    }
                }
            }
            function findItemByClassName(collection, value) {
                for (var i = 0; i < collection.length; i++) {
                    if (collection[i].className == value) {
                        return collection[i];
                    }
                }
            }
            //end utils
            //key evaluators
            function isHKeyMatch(hIndex, slength) {
                return (hIndex.match(/_/g) || []).length == slength;
            }
            //end key evaluators
            //methods
            async function clickInnerDetailTableInputByHeirarchyIndex(sender, args, index, negation) {
                var e = args.get_domEvent();
                var hIndexOfInvoker = args.get_itemIndexHierarchical();
                if (isHKeyMatch(hIndexOfInvoker, index)) {
                    var myId = args.get_id();
                    var myElement = document.getElementById(myId);
                    var sl = myElement.nextSibling;
                    var finder = findItemByKey("vAlign", sl.childNodes, "top", false);
                    if (finder) {
                        var thead = findItemByKey("nodeName", finder.firstChild.childNodes, "THEAD", false);

                        var tr = findItemByKey("id", thead.childNodes, undefined, true);

                        var rgCheck = findItemByClassName(tr.childNodes, "rgHeader rgCheck");

                        var checkBox = findItemByKey("type", rgCheck.childNodes, "checkbox", false);
                        if (!negation) {
                            if (!checkBox.checked)
                                checkBox.click();
                        }
                        else {
                            if (checkBox.checked)
                                checkBox.click();
                        }
                    }
                }
            }
            async function RCG_RowSelected(sender, args) {
                clickInnerDetailTableInputByHeirarchyIndex(sender, args, 0, false);
                clickInnerDetailTableInputByHeirarchyIndex(sender, args, 1, false);
            }
            async function RCG_RowDeselected(sender, args) {
                clickInnerDetailTableInputByHeirarchyIndex(sender, args, 0, true);
                clickInnerDetailTableInputByHeirarchyIndex(sender, args, 1, true);
            }
            async function BPG_RowSelected(sender, args) {
                clickInnerDetailTableInputByHeirarchyIndex(sender, args, 0, false);
            }
            async function BPG_RowDeselected(sender, args) {
                clickInnerDetailTableInputByHeirarchyIndex(sender, args, 0, true);
            }
            //end events
        </script>
        <!-- End Client Scripts-->
    </telerik:RadCodeBlock>
    <div class="row">
        <asp:LinkButton ID="lbPostback" runat="server" Text="Post back"  OnClick="lbPostback_Click"/>
        <br/>

        <telerik:RadGrid ID="RadGrid1" runat="server" ShowStatusBar="true" AutoGenerateColumns="False" AllowSorting="True" AllowMultiRowSelection="True"  AllowPaging="False"
			OnDetailTableDataBind="RadGrid1_DetailTableDataBind" OnNeedDataSource="RadGrid1_NeedDataSource" AllowAutomaticDeletes="True" AllowAutomaticUpdates="True" RetainExpandStateOnRebind="True"
			OnPreRender="RadGrid1_PreRender">
            <ClientSettings AllowExpandCollapse="True">
                <Selecting AllowRowSelect="true" UseClientSelectColumnOnly="True"  />
                <ClientEvents OnRowSelected="BPG_RowSelected" OnRowDeselected="BPG_RowDeselected"  />
            </ClientSettings>
			<MasterTableView DataKeyNames="CustomerID" AllowMultiColumnSorting="True" AllowPaging="false" HierarchyLoadMode="Client">
				<DetailTables>
					<telerik:GridTableView DataKeyNames="OrderID" Name="Orders" Width="100%" HierarchyLoadMode="Client">
						<DetailTables>
							<telerik:GridTableView DataKeyNames="OrderID" Name="OrderDetails" Width="100%">
								<Columns>
                                    <telerik:GridBoundColumn SortExpression="UnitPrice" HeaderText="Unit Price" HeaderButtonType="TextButton"
										DataField="UnitPrice">
									</telerik:GridBoundColumn>
									<telerik:GridBoundColumn SortExpression="OrderQty" HeaderText="Quantity" HeaderButtonType="TextButton"
										DataField="OrderQty">
									</telerik:GridBoundColumn>
									<telerik:GridBoundColumn SortExpression="UnitPriceDiscount" HeaderText="Discount" HeaderButtonType="TextButton"
										DataField="UnitPriceDiscount">
									</telerik:GridBoundColumn>
								</Columns>
							</telerik:GridTableView>
						</DetailTables>
						<Columns>
                            <telerik:GridClientSelectColumn UniqueName="ClientSelectColumn" Display="True" HeaderStyle-Width="55px" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" />
							<telerik:GridBoundColumn SortExpression="OrderID" HeaderText="OrderID" HeaderButtonType="TextButton"
								DataField="SalesOrderID">
							</telerik:GridBoundColumn>
							<telerik:GridBoundColumn SortExpression="OrderDate" HeaderText="Date Ordered" HeaderButtonType="TextButton"
								DataField="OrderDate" UniqueName="OrderDate" DataFormatString="{0:D}">
							</telerik:GridBoundColumn>
							<telerik:GridBoundColumn SortExpression="Freight" HeaderText="Freight" HeaderButtonType="TextButton"
								DataField="Freight" UniqueName="Freight">
							</telerik:GridBoundColumn>
						</Columns>
					</telerik:GridTableView>
				</DetailTables>
				<Columns>
                    <telerik:GridClientSelectColumn UniqueName="ClientSelectColumn" Display="True" HeaderStyle-Width="55px" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" />
					<telerik:GridBoundColumn SortExpression="CustomerID" HeaderText="CustomerID" HeaderButtonType="TextButton"
						DataField="CustomerID">
					</telerik:GridBoundColumn>
					<telerik:GridBoundColumn SortExpression="ContactName" HeaderText="Contact Name" HeaderButtonType="TextButton"
						DataField="ContactName">
					</telerik:GridBoundColumn>
					<telerik:GridBoundColumn SortExpression="CompanyName" HeaderText="Company" HeaderButtonType="TextButton"
						DataField="CompanyName">
					</telerik:GridBoundColumn>
				</Columns>
			</MasterTableView>
		</telerik:RadGrid>
    </div>
    <%--<div class="jumbotron">
        <h1>ASP.NET</h1>
        <p class="lead">ASP.NET is a free web framework for building great Web sites and Web applications using HTML, CSS, and JavaScript.</p>
        <p><a href="http://www.asp.net" class="btn btn-primary btn-lg">Learn more &raquo;</a></p>
    </div>

    <div class="row">
        <div class="col-md-4">
            <h2>Getting started</h2>
            <p>
                ASP.NET Web Forms lets you build dynamic websites using a familiar drag-and-drop, event-driven model.
            A design surface and hundreds of controls and components let you rapidly build sophisticated, powerful UI-driven sites with data access.
            </p>
            <p>
                <a class="btn btn-default" href="https://go.microsoft.com/fwlink/?LinkId=301948">Learn more &raquo;</a>
            </p>
        </div>
        <div class="col-md-4">
            <h2>Get more libraries</h2>
            <p>
                NuGet is a free Visual Studio extension that makes it easy to add, remove, and update libraries and tools in Visual Studio projects.
            </p>
            <p>
                <a class="btn btn-default" href="https://go.microsoft.com/fwlink/?LinkId=301949">Learn more &raquo;</a>
            </p>
        </div>
        <div class="col-md-4">
            <h2>Web Hosting</h2>
            <p>
                You can easily find a web hosting company that offers the right mix of features and price for your applications.
            </p>
            <p>
                <a class="btn btn-default" href="https://go.microsoft.com/fwlink/?LinkId=301950">Learn more &raquo;</a>
            </p>
        </div>
    </div>--%>

</asp:Content>
