<%@ Page Language="VB" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<!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">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" 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" />                
            </Scripts>
        </asp:ScriptManager>
        <div>
            <telerik:RadCodeBlock ID="CodeBlock" runat="server">

                <script type="text/javascript">
        
                        function pageLoad()
                        {
                            window.$ = jQuery = $telerik.$;
                        }
                
                        
                        function keyPressed(sender, args)
                        {
                            if (args.get_domEvent().keyCode == 13)
                            {
                                var grid = $find('<%=RadGrid1.ClientID%>');
                                var masterTable = grid.get_masterTableView();
                                
                                $(sender.get_element()).parents("tr:first").next("tr:first").find("input")[0].focus();
                            }
                        }
        
                </script>

            </telerik:RadCodeBlock>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
                SelectCommand="SELECT [EmployeeID], [LastName], [City] FROM [Employees]" ConflictDetection="CompareAllValues"
                DeleteCommand="DELETE FROM [Employees] WHERE [EmployeeID] = @original_EmployeeID AND [LastName] = @original_LastName AND (([City] = @original_City) OR ([City] IS NULL AND @original_City IS NULL))"
                InsertCommand="INSERT INTO [Employees] ([LastName], [City]) VALUES (@LastName, @City)"
                OldValuesParameterFormatString="original_{0}" UpdateCommand="UPDATE [Employees] SET [LastName] = @LastName, [City] = @City WHERE [EmployeeID] = @original_EmployeeID AND [LastName] = @original_LastName AND (([City] = @original_City) OR ([City] IS NULL AND @original_City IS NULL))">
                <DeleteParameters>
                    <asp:Parameter Name="original_EmployeeID" Type="Int32" />
                    <asp:Parameter Name="original_LastName" Type="String" />
                    <asp:Parameter Name="original_City" Type="String" />
                </DeleteParameters>
                <UpdateParameters>
                    <asp:Parameter Name="LastName" Type="String" />
                    <asp:Parameter Name="City" Type="String" />
                    <asp:Parameter Name="original_EmployeeID" Type="Int32" />
                    <asp:Parameter Name="original_LastName" Type="String" />
                    <asp:Parameter Name="original_City" Type="String" />
                </UpdateParameters>
                <InsertParameters>
                    <asp:Parameter Name="LastName" Type="String" />
                    <asp:Parameter Name="City" Type="String" />
                </InsertParameters>
            </asp:SqlDataSource>
        </div>
        <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
            SelectCommand="SELECT DISTINCT [City] FROM [Employees]"></asp:SqlDataSource>
        <telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1" GridLines="None"
            OnItemCreated="RadGrid1_ItemCreated" AutoGenerateDeleteColumn="true">
            <MasterTableView AutoGenerateColumns="False" AllowAutomaticInserts="true" AllowAutomaticUpdates="true"
                AllowAutomaticDeletes="true" CellSpacing="-1" PageSize="5" DataKeyNames="EmployeeID"
                DataSourceID="SqlDataSource1">
                <Columns>
                    <telerik:GridEditCommandColumn>
                    </telerik:GridEditCommandColumn>
                    <telerik:GridBoundColumn DataField="EmployeeID" DataType="System.Int32" HeaderText="EmployeeID"
                        ReadOnly="True" SortExpression="EmployeeID" UniqueName="EmployeeID">
                    </telerik:GridBoundColumn>
                    <telerik:GridTemplateColumn DataField="City" HeaderText="City" UniqueName="City">
                        <ItemTemplate>
                            <asp:Label ID="lblCity" runat="server" Text='<%#Eval("City") %>'>
                            </asp:Label>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <telerik:RadComboBox ID="cmbConfirm" AllowCustomText="true" AutoPostBack="false" OnClientKeyPressing="keyPressed"
                                DataTextField="City" DataValueField="City" DataSourceID="SqlDataSource2" SelectedValue='<%#Bind("City") %>'
                                runat="server">
                            </telerik:RadComboBox>
                        </EditItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridBoundColumn DataField="LastName" HeaderText="LastName" SortExpression="LastName"
                        UniqueName="LastName">
                    </telerik:GridBoundColumn>
                </Columns>
            </MasterTableView>
            <ClientSettings Selecting-AllowRowSelect="true">
            </ClientSettings>
        </telerik:RadGrid>
    </form>
</body>
</html>
