<%@ Page Language="c#" CodeFile="DefaultCS.aspx.cs" Inherits="Telerik.GridExamplesCSharp.Hierarchy.NestedViewTemplate.DefaultCS" %>

<%@ Register TagPrefix="telerik" Namespace="Telerik.Charting" Assembly="Telerik.Web.UI" %>
<%@ 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">
    <style type="text/css">
        .viewWrap
        {
            padding: 15px;
            background: #2291b5 0 0 url(Img/bluegradient.gif) repeat-x;
        }
        
        .contactWrap
        {
            padding: 10px 15px 15px 15px;
            background: #fff;
            color: #333;
        }
        
        .contactWrap td
        {
            padding: 0 20px 0 0;
        }
        
        .contactWrap td td
        {
            padding: 3px 20px 3px 0;
        }
        
        .contactWrap img
        {
            border: 1px solid #05679d;
        }
    </style>
</head>
<body class="BODY">
    <form runat="server" id="mainForm" method="post">
    <telerik:RadScriptManager runat="server" ID="ScriptManager1">
    </telerik:RadScriptManager>
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadGrid1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" />
    <div class="bigModule">
        <div class="bigModuleBottom">
            The <b>Hierarchy with templates</b> grid demo shows how to have a structure resembling
            a standard hierarchy, which can be greatly customized, without setting hierarchical
            relations between the master and detail levels.
            <br />
            The example shows a list of sales employees. In the detail table for each employee
            is the relevant information for all the sales made by the person, his/her contact
            information, along with a photograph, and a chart representing the sales revenue,
            broken down per product category.
        </div>
    </div>
    <telerik:RadGrid ID="RadGrid1" OnPreRender="RadGrid1_PreRender" DataSourceID="SqlDataSource1"
        runat="server" AutoGenerateColumns="False" AllowSorting="True" AllowMultiRowSelection="False"
        AllowPaging="True" PageSize="5" GridLines="None" ShowGroupPanel="true" OnItemCreated="RadGrid1_ItemCreated"
        OnItemCommand="RadGrid1_ItemCommand">
        <PagerStyle Mode="NumericPages"></PagerStyle>
        <MasterTableView DataSourceID="SqlDataSource1" DataKeyNames="EmployeeID" AllowMultiColumnSorting="True"
            GroupLoadMode="Server">
            <NestedViewTemplate>
                <asp:Panel runat="server" ID="InnerContainer" CssClass="viewWrap" Visible="false">
                    <telerik:RadTabStrip runat="server" ID="TabStip1" MultiPageID="Multipage1" SelectedIndex="0">
                        <Tabs>
                            <telerik:RadTab runat="server" Text="Sales" PageViewID="PageView1">
                            </telerik:RadTab>
                            <telerik:RadTab runat="server" Text="Contact Information" PageViewID="PageView2">
                            </telerik:RadTab>
                        </Tabs>
                    </telerik:RadTabStrip>
                    <telerik:RadMultiPage runat="server" ID="Multipage1" SelectedIndex="0" RenderSelectedPageOnly="false">
                        <telerik:RadPageView runat="server" ID="PageView1">
                            <asp:Label ID="Label1" Font-Bold="true" Font-Italic="true" Text='<%# Eval("EmployeeID") %>'
                                Visible="false" runat="server" />
                            <telerik:RadGrid runat="server" ID="OrdersGrid" DataSourceID="SqlDataSource2" ShowFooter="true"
                                AllowSorting="true" EnableLinqExpressions="false">
                                <MasterTableView ShowHeader="true" AutoGenerateColumns="False" AllowPaging="true"
                                    DataKeyNames="OrderID" PageSize="7" HierarchyLoadMode="ServerOnDemand">
                                    <DetailTables>
                                        <telerik:GridTableView AutoGenerateColumns="false" DataKeyNames="OrderID" DataSourceID="SqlDataSource3"
                                            Width="100%">
                                            <ParentTableRelation>
                                                <telerik:GridRelationFields DetailKeyField="OrderID" MasterKeyField="OrderID" />
                                            </ParentTableRelation>
                                            <Columns>
                                                <telerik:GridBoundColumn SortExpression="ProductName" HeaderText="Product name" HeaderButtonType="TextButton"
                                                    DataField="ProductName" UniqueName="ProductName">
                                                </telerik:GridBoundColumn>
                                                <telerik:GridNumericColumn SortExpression="UnitPrice" HeaderText="Unit Price" HeaderButtonType="TextButton"
                                                    DataField="UnitPrice" DataFormatString="{0:C}" Aggregate="Avg" FooterAggregateFormatString="Average price: {0:C}">
                                                </telerik:GridNumericColumn>
                                                <telerik:GridNumericColumn SortExpression="Quantity" HeaderText="Quantity" HeaderButtonType="TextButton"
                                                    DataField="Quantity" Aggregate="Max" FooterAggregateFormatString="Max quantity: {0}">
                                                </telerik:GridNumericColumn>
                                                <telerik:GridNumericColumn SortExpression="Discount" HeaderText="Discount" HeaderButtonType="TextButton"
                                                    DataField="Discount" DataFormatString="{0:P}">
                                                </telerik:GridNumericColumn>
                                                <telerik:GridCalculatedColumn UniqueName="Total" DataFields="UnitPrice,Quantity,Discount"
                                                    Expression="IIf({2} = 0,{0}*{1}, {0}*{1}*{2})" HeaderText="Total" DataType="System.Double"
                                                    Aggregate="Sum" DataFormatString="{0:C}" FooterAggregateFormatString="Total cost: {0:C}" />
                                            </Columns>
                                            <SortExpressions>
                                                <telerik:GridSortExpression FieldName="Quantity" SortOrder="Descending"></telerik:GridSortExpression>
                                            </SortExpressions>
                                        </telerik:GridTableView>
                                    </DetailTables>
                                    <Columns>
                                        <telerik:GridNumericColumn SortExpression="CompanyName" HeaderText="Customer" HeaderButtonType="TextButton"
                                            DataField="CompanyName" UniqueName="CompanyName">
                                        </telerik:GridNumericColumn>
                                        <telerik:GridBoundColumn SortExpression="OrderID" HeaderText="OrderID" HeaderButtonType="TextButton"
                                            DataField="OrderID" UniqueName="OrderID" Aggregate="Count" FooterAggregateFormatString="Orders count: {0}">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridDateTimeColumn SortExpression="OrderDate" HeaderText="Order date" HeaderButtonType="TextButton"
                                            DataField="OrderDate" UniqueName="OrderDate" DataFormatString="{0:MM/dd/yyyy}"
                                            Aggregate="Last" FooterAggregateFormatString="Last order dates: {0:d}">
                                        </telerik:GridDateTimeColumn>
                                        <telerik:GridBoundColumn UniqueName="Total" DataField="Total" HeaderText="Order Total"
                                            SortExpression="Total" DataFormatString="{0:C}">
                                        </telerik:GridBoundColumn>
                                    </Columns>
                                </MasterTableView>
                            </telerik:RadGrid>
                            <asp:SqlDataSource ID="SqlDataSource2" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
                                ProviderName="System.Data.SqlClient" SelectCommand="SELECT Orders.OrderID, Orders.OrderDate, Orders.Freight, Customers.CompanyName, SUM(
                                    CASE WHEN [Order Details].Discount = 0 	THEN 1 
	                                ELSE [Order Details].Discount END 
                                    * [Order Details].Quantity * [Order Details].UnitPrice) as Total	 
                                    FROM (Orders LEFT JOIN Customers on Orders.CustomerID = Customers.CustomerID) 
                                    FULL JOIN [Order Details] on Orders.OrderID = [Order Details].OrderID 
                                    Where EmployeeID = @EmployeeID 
                                    GROUP BY Orders.OrderID,Orders.OrderDate, Orders.Freight, Customers.CompanyName"
                                runat="server">
                                <SelectParameters>
                                    <asp:ControlParameter ControlID="Label1" PropertyName="Text" Type="String" Name="EmployeeID" />
                                </SelectParameters>
                            </asp:SqlDataSource>
                            <asp:SqlDataSource ID="SqlDataSource3" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
                                ProviderName="System.Data.SqlClient" SelectCommand="SELECT OrderID, [Order Details].UnitPrice, Quantity, Discount, Products.ProductName FROM ([Order Details] LEFT JOIN Products on [Order Details].ProductID = Products.ProductID) where OrderID = @OrderID"
                                runat="server">
                                <SelectParameters>
                                    <asp:SessionParameter Name="OrderID" SessionField="OrderID" Type="Int32" />
                                </SelectParameters>
                            </asp:SqlDataSource>
                        </telerik:RadPageView>
                        <telerik:RadPageView runat="server" ID="PageView2" Width="560px">
                            <div class="contactWrap">
                                <table cellpadding="0" cellspacing="0">
                                    <tr>
                                        <td>
                                            <%--<img src='<%# "Img/" + (Container.FindControl("Label1") as Label).Text  %>.jpg' alt="Customer Image" />--%>
                                        </td>
                                        <td>
                                            <telerik:RadGrid runat="server" ID="ContactInformationGrid" AllowPaging="true" AutoGenerateColumns="false"
                                                DataSourceID="SqlDataSource4" AllowAutomaticUpdates="true" AutoGenerateEditColumn="true"
                                                Width="100%">
                                                <MasterTableView DataKeyNames="EmployeeID">
                                                    <Columns>
                                                        <telerik:GridBoundColumn DataFormatString="{0:MM/dd/yyyy}" HeaderText="BirthDate:"
                                                            HtmlEncode="false" DataField="BirthDate" HeaderStyle-Font-Italic="false" HeaderStyle-Font-Bold="true" />
                                                        <telerik:GridBoundColumn HeaderStyle-Font-Italic="false" HeaderStyle-Font-Bold="true"
                                                            HeaderText="Country:" DataField="Country" />
                                                        <telerik:GridBoundColumn HeaderText="City:" DataField="City" HeaderStyle-Font-Italic="false"
                                                            HeaderStyle-Font-Bold="true" />
                                                        <telerik:GridBoundColumn HeaderText="Address:" DataField="Address" HeaderStyle-Font-Italic="false"
                                                            HeaderStyle-Font-Bold="true" />
                                                        <telerik:GridBoundColumn HeaderText="HomePhone:" DataField="HomePhone" HeaderStyle-Font-Italic="false"
                                                            HeaderStyle-Font-Bold="true" />
                                                    </Columns>
                                                </MasterTableView>
                                            </telerik:RadGrid>
                                            <%-- <asp:DetailsView ID="DetailsView1" AllowPaging="true" GridLines="None" Width="100%"
                                                DataSourceID="SqlDataSource4" runat="server" Font-Italic="true" AutoGenerateRows="false">
                                                <Fields>
                                                    <asp:BoundField DataFormatString="{0:MM/dd/yyyy}" HeaderText="BirthDate:" HtmlEncode="false"
                                                        DataField="BirthDate" HeaderStyle-Font-Italic="false" HeaderStyle-Font-Bold="true" />
                                                    <asp:BoundField HeaderStyle-Font-Italic="false" HeaderStyle-Font-Bold="true" HeaderText="Country:"
                                                        DataField="Country" />
                                                    <asp:BoundField HeaderText="City:" DataField="City" HeaderStyle-Font-Italic="false"
                                                        HeaderStyle-Font-Bold="true" />
                                                    <asp:BoundField HeaderText="Address:" DataField="Address" HeaderStyle-Font-Italic="false"
                                                        HeaderStyle-Font-Bold="true" />
                                                    <asp:BoundField HeaderText="HomePhone:" DataField="HomePhone" HeaderStyle-Font-Italic="false"
                                                        HeaderStyle-Font-Bold="true" />
                                                </Fields>
                                            </asp:DetailsView>--%>
                                            <%--<asp:SqlDataSource ID="SqlDataSource4" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
                                                ProviderName="System.Data.SqlClient" 
                                                SelectCommand="SELECT BirthDate, Country, City, Address, HomePhone FROM Employees Where EmployeeID = @EmployeeID"
                                                runat="server">
                                                <SelectParameters>
                                                    <asp:ControlParameter ControlID="Label1" PropertyName="Text" Type="String" Name="EmployeeID" />
                                                </SelectParameters>
                                            </asp:SqlDataSource>--%>
                                            <asp:SqlDataSource ID="SqlDataSource4" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
                                                ProviderName="System.Data.SqlClient" SelectCommand="SELECT EmployeeID, BirthDate, Country, City, Address, HomePhone FROM Employees Where EmployeeID = @EmployeeID"
                                                UpdateCommand="UPDATE [Employees] SET [BirthDate] = @BirthDate, [Address] = @Address, [City] = @City, [Country] = @Country, [HomePhone] = @HomePhone WHERE [EmployeeID] = @EmployeeID"
                                                runat="server">
                                                <SelectParameters>
                                                    <asp:ControlParameter ControlID="Label1" PropertyName="Text" Type="String" Name="EmployeeID" />
                                                </SelectParameters>
                                                <UpdateParameters>
                                                    <asp:Parameter Name="BirthDate" Type="DateTime" />
                                                    <asp:Parameter Name="Address" Type="String" />
                                                    <asp:Parameter Name="City" Type="String" />
                                                    <asp:Parameter Name="Country" Type="String" />
                                                    <asp:Parameter Name="HomePhone" Type="String" />
                                                    <asp:Parameter Name="EmployeeID" Type="Int32" />
                                                </UpdateParameters>
                                            </asp:SqlDataSource>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                        </telerik:RadPageView>
                    </telerik:RadMultiPage>
                </asp:Panel>
            </NestedViewTemplate>
            <Columns>
                <telerik:GridBoundColumn SortExpression="FirstName" HeaderText="First Name" HeaderButtonType="TextButton"
                    DataField="FirstName" UniqueName="FirstName">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn SortExpression="LastName" HeaderText="Last Name" HeaderButtonType="TextButton"
                    DataField="LastName" UniqueName="LastName">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn SortExpression="Title" HeaderText="Title" HeaderButtonType="TextButton"
                    DataField="Title" UniqueName="Title">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn SortExpression="BirthDate" DataFormatString="{0:MM/dd/yyyy}"
                    HeaderText="Birth Date" HeaderButtonType="TextButton" DataField="BirthDate" UniqueName="BirthDate">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn SortExpression="City" HeaderText="City" HeaderButtonType="TextButton"
                    DataField="City" UniqueName="City">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn SortExpression="Country" HeaderText="Country" HeaderButtonType="TextButton"
                    DataField="Country" UniqueName="Country">
                </telerik:GridBoundColumn>
            </Columns>
        </MasterTableView>
        <ClientSettings AllowDragToGroup="true" />
    </telerik:RadGrid>
    <asp:SqlDataSource ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
        ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM Employees"
        runat="server"></asp:SqlDataSource>
    </form>
</body>
</html>
