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

<!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></title>
    <telerik:RadStyleSheetManager ID="RadStyleSheetManager1" runat="server" />
</head>
<body>
    <form id="form1" runat="server">
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
            <Scripts>
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
            </Scripts>
        </telerik:RadScriptManager>
        <telerik:RadAjaxManager runat="server" ID="RadAjaxManager1">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadGrid1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>

        <div class="qsf-demo-canvas">
            <telerik:RadGrid ID="RadGrid1" GridLines="None" AutoGenerateColumns="false" PageSize="10"
                AllowPaging="true" AllowSorting="true" runat="server"
                DataSourceID="ProductsDataSource" AllowAutomaticUpdates="true" AllowAutomaticInserts="True"
                ShowStatusBar="true">
                <MasterTableView ShowFooter="false" DataKeyNames="ProductID" EditMode="InPlace" CommandItemDisplay="TopAndBottom">
                    <Columns>
                        <telerik:GridBoundColumn DataField="ProductName" HeaderText="ProductName"
                            HeaderStyle-Width="300px" ItemStyle-Width="300px" />
                        <telerik:GridTemplateColumn UniqueName="Supplier" HeaderText="Supplier"
                            SortExpression="CompanyName" ItemStyle-Width="400px">
                            <FooterTemplate>Template footer</FooterTemplate>
                            <FooterStyle VerticalAlign="Middle" HorizontalAlign="Center" />
                            <ItemTemplate>
                                <%#DataBinder.Eval(Container.DataItem, "CompanyName")%>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <telerik:RadComboBox runat="server" ID="RadComboBox1" EnableLoadOnDemand="True" DataTextField="CompanyName"
                                    OnItemsRequested="RadComboBox1_ItemsRequested" DataValueField="SupplierID" AutoPostBack="true"
                                    HighlightTemplatedItems="true" Height="140px" Width="220px" DropDownWidth="420px"
                                    OnSelectedIndexChanged="OnSelectedIndexChangedHandler">
                                    <ItemTemplate>
                                        <%# DataBinder.Eval(Container, "Text")%>
                                    </ItemTemplate>
                                </telerik:RadComboBox>
                            </EditItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridTemplateColumn UniqueName="ContactName" HeaderText="ContactName"
                            SortExpression="CompanyName" ItemStyle-Width="400px">
                            <ItemTemplate>
                                <%#DataBinder.Eval(Container.DataItem, "CategoryID")%>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <telerik:RadComboBox runat="server" ID="RadComboBox2" EnableLoadOnDemand="True" DataTextField="ContactName"
                                    OnItemsRequested="RadComboBox2_ItemsRequested" DataValueField="ContactName" AutoPostBack="true"
                                    HighlightTemplatedItems="true" Height="140px" Width="220px" DropDownWidth="420px"
                                    OnSelectedIndexChanged="RadComboBox2_SelectedIndexChanged">
                                    <ItemTemplate>
                                        <%# DataBinder.Eval(Container, "Text")%>
                                    </ItemTemplate>
                                </telerik:RadComboBox>
                            </EditItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridEditCommandColumn FooterText="EditCommand footer" UniqueName="EditCommandColumn"
                            HeaderText="Edit" HeaderStyle-Width="100px" UpdateText="Update">
                        </telerik:GridEditCommandColumn>
                    </Columns>
                </MasterTableView>
            </telerik:RadGrid>
        </div>
        <asp:SqlDataSource ID="ProductsDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
            SelectCommand="SELECT products.[ProductID], products.[ProductName], products.[SupplierID], products.[CategoryID],
                                     suppliers.[CompanyName], suppliers.[ContactName],
                                     categories.[CategoryName]
                                     FROM [Products] AS products
                                     INNER JOIN Suppliers AS suppliers
                                     ON products.SupplierID = suppliers.SupplierID
                                     INNER JOIN Categories AS categories
                                     ON products.CategoryID = categories.CategoryID"
            InsertCommand="INSERT INTO [Products] ([ProductName], [SupplierID], [CategoryID]) VALUES (@ProductName, @SupplierID, @CategoryID)"
            UpdateCommand="UPDATE [Products] SET  [ProductName] = @ProductName, [SupplierID] = @SupplierID, [CategoryID] = @CategoryID WHERE [ProductID] = @ProductID">
            <InsertParameters>
                <asp:Parameter Name="ProductName" Type="String" />
                <asp:SessionParameter SessionField="SupplierID" Name="SupplierID" Type="Int32" />
                <asp:SessionParameter SessionField="CategoryID" Name="CategoryID" Type="Int32" />
            </InsertParameters>
            <UpdateParameters>
                <asp:Parameter Name="ProductID" Type="Int32" />
                <asp:Parameter Name="ProductName" Type="String" />
                <asp:SessionParameter SessionField="SupplierID" Name="SupplierID" Type="Int32" />
                <asp:SessionParameter SessionField="CategoryID" Name="CategoryID" Type="Int32" />
            </UpdateParameters>
        </asp:SqlDataSource>

        <asp:SqlDataSource ID="CategoriesDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
            SelectCommand="SELECT [CategoryID], [CategoryName] FROM [Categories]"></asp:SqlDataSource>
    </form>
</body>
</html>
