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

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<!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 id="Head1" runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager runat="server" ID="ScriptManager1">
        </asp:ScriptManager>
        <telerik:RadAjaxPanel runat="server" ID="RadAjaxPanel1">
            <telerik:RadGrid ID="RadGrid1" runat="server" AllowAutomaticDeletes="True" AllowAutomaticInserts="True" AutoGenerateColumns="false"
                AllowAutomaticUpdates="True" AutoGenerateEditColumn="True" DataSourceID="SqlDataSource1"
                GridLines="None" AllowPaging="True" AllowSorting="True" ShowStatusBar="True"
                OnUpdateCommand="RadGrid1_UpdateCommand" OnPreRender="RadGrid1_PreRender">
                <MasterTableView DataKeyNames="CustomerID" DataSourceID="SqlDataSource1"
                    HierarchyDefaultExpanded="false">
                    <Columns>
                        <telerik:GridBoundColumn DataField="CustomerID" HeaderText="CustomerID" ReadOnly="true">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="CompanyName" HeaderText="CompanyName">
                        </telerik:GridBoundColumn>
                    </Columns>
                    <DetailTables>
                        <telerik:GridTableView runat="server" DataKeyNames="CustomerID, OrderID" DataSourceID="SqlDataSource2"
                            HierarchyDefaultExpanded="false" Width="100%">
                            <ParentTableRelation>
                                <telerik:GridRelationFields DetailKeyField="CustomerID" MasterKeyField="CustomerID" />
                            </ParentTableRelation>
                            <Columns>
                                <telerik:GridBoundColumn DataField="CustomerID" HeaderText="CustomerID" ReadOnly="true">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="OrderID" HeaderText="OrderID" ReadOnly="true">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="OrderDate" HeaderText="OrderDate">
                                </telerik:GridBoundColumn>
                            </Columns>
                            <DetailTables>
                                <telerik:GridTableView runat="server" DataKeyNames="OrderID" DataSourceID="SqlDataSource3"
                                    Width="100%" Name="OrderDetails">
                                    <ParentTableRelation>
                                        <telerik:GridRelationFields DetailKeyField="OrderID" MasterKeyField="OrderID" />
                                    </ParentTableRelation>
                                    <Columns>
                                        <telerik:GridBoundColumn DataField="OrderID" HeaderText="OrderID" ReadOnly="true" ForceExtractValue="InEditMode">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="ProductID" HeaderText="ProductID" ReadOnly="true" ForceExtractValue="InEditMode">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="UnitPrice" HeaderText="UnitPrice">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="Quantity" HeaderText="Quantity">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="Discount" HeaderText="Discount">
                                        </telerik:GridBoundColumn>
                                    </Columns>
                                </telerik:GridTableView>
                            </DetailTables>
                        </telerik:GridTableView>
                    </DetailTables>
                </MasterTableView>
            </telerik:RadGrid>
        </telerik:RadAjaxPanel>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
            SelectCommand="SELECT TOP 3 [CustomerID], [CompanyName] FROM [Customers]" UpdateCommand="UPDATE [Customers] SET [CompanyName] = @CompanyName WHERE [CustomerID] = @CustomerID">
            <UpdateParameters>
                <asp:Parameter Name="CompanyName" Type="String" />
                <asp:Parameter Name="CustomerID" Type="String" />
            </UpdateParameters>
        </asp:SqlDataSource>
        <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>"
            SelectCommand="SELECT [CustomerID],[OrderID], [OrderDate] FROM [Orders] WHERE ([CustomerID] = @CustomerID)"
            UpdateCommand="UPDATE [Orders] SET [OrderDate] = @OrderDate WHERE [OrderID] = @OrderID">
            <SelectParameters>
                <asp:ControlParameter ControlID="RadGrid1" Name="CustomerID" PropertyName="SelectedValue"
                    Type="String" />
            </SelectParameters>
            <UpdateParameters>
                <asp:Parameter Name="OrderDate" Type="DateTime" />
                <asp:Parameter Name="OrderID" Type="Int32" />
            </UpdateParameters>
        </asp:SqlDataSource>
        <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString3 %>"
            SelectCommand="SELECT * FROM [Order Details] WHERE ([OrderID] = @OrderID)" UpdateCommand="UPDATE [Order Details] SET [UnitPrice] = @UnitPrice, [Quantity] = @Quantity, [Discount] = @Discount WHERE [OrderID] = @OrderID AND [ProductID] = @ProductID">
            <SelectParameters>
                <asp:ControlParameter ControlID="RadGrid1" Name="OrderID" PropertyName="SelectedValue"
                    Type="Int32" />
            </SelectParameters>
            <UpdateParameters>
                <asp:Parameter Name="UnitPrice" Type="Decimal" />
                <asp:Parameter Name="Quantity" Type="Int16" />
                <asp:Parameter Name="Discount" Type="Single" />
                <asp:Parameter Name="OrderID" Type="Int32" />
                <asp:Parameter Name="ProductID" Type="Int32" />
            </UpdateParameters>
        </asp:SqlDataSource>
    </div>
    </form>
</body>
</html>
