<%@ 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 runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager runat="server" ID="ScriptManager1">
    </asp:ScriptManager>
    <div>
        <telerik:RadGrid runat="server" ID="RadGrid1" AllowPaging="True" 
            AllowSorting="True" AutoGenerateDeleteColumn="True" 
            AutoGenerateEditColumn="True" DataSourceID="SqlDataSource1" GridLines="None"
            AllowAutomaticDeletes="true" AllowAutomaticInserts="true" AllowAutomaticUpdates="true">
            <MasterTableView AutoGenerateColumns="False" DataKeyNames="TerritoryID" 
                            DataSourceID="SqlDataSource1">
                <Columns>
                    <telerik:GridBoundColumn DataField="TerritoryID" HeaderText="Territory ID" 
                        ReadOnly="True" SortExpression="TerritoryID" UniqueName="TerritoryID">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="TerritoryDescription" 
                        HeaderText="Territory Description" SortExpression="TerritoryDescription" 
                        UniqueName="TerritoryDescription">
                    </telerik:GridBoundColumn>                    
                    <telerik:GridDropDownColumn DataField="RegionID" UniqueName="Region"  
                        HeaderText="Region"
                        ListTextField="RegionDescription" ListValueField="RegionID"
                        DataSourceID="SqlDataSource2">
                    </telerik:GridDropDownColumn>
                </Columns>
            </MasterTableView>
        </telerik:RadGrid>
        
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" 
            DeleteCommand="DELETE FROM [Territories] WHERE [TerritoryID] = @TerritoryID" 
            InsertCommand="INSERT INTO [Territories] ([TerritoryID], [TerritoryDescription], [RegionID]) VALUES (@TerritoryID, @TerritoryDescription, @RegionID)" 
            SelectCommand="SELECT * FROM [Territories]" 
            UpdateCommand="UPDATE [Territories] SET [TerritoryDescription] = @TerritoryDescription, [RegionID] = @RegionID WHERE [TerritoryID] = @TerritoryID">
            <DeleteParameters>
                <asp:Parameter Name="TerritoryID" Type="String" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="TerritoryDescription" Type="String" />
                <asp:Parameter Name="RegionID" Type="Int32" />
                <asp:Parameter Name="TerritoryID" Type="String" />
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="TerritoryID" Type="String" />
                <asp:Parameter Name="TerritoryDescription" Type="String" />
                <asp:Parameter Name="RegionID" Type="Int32" />
            </InsertParameters>
        </asp:SqlDataSource>
        
        <asp:SqlDataSource runat="server" ID="SqlDataSource2" 
            ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" 
            SelectCommand="SELECT [RegionID], [RegionDescription] FROM [Region]">
        </asp:SqlDataSource>
        
    </div>
    </form>
</body>
</html>
