<%@ 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>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <div>
            <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
                <AjaxSettings>
                    <telerik:AjaxSetting AjaxControlID="RadGrid1">
                        <UpdatedControls>
                            <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                        </UpdatedControls>
                    </telerik:AjaxSetting>
                </AjaxSettings>
            </telerik:RadAjaxManager>
            <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
            <script type="text/javascript">
            function KeyPressing(sender, eventArgs)
            {
                if(eventArgs.get_domEvent().keyCode == 13)
                {
                    var grid = $find("<%= RadGrid1.ClientID %>");
                    var rows = grid.get_masterTableView().get_dataItems();
                    var rowCount = rows.length;
                    var comboID = sender.get_id();
                    var currentRow, nextRow, tempComboID, nextComboID;
                    var i = 0;
                    for(i = 0; i < rowCount; i++)
                    {
                        if(rows[i].get_element().childNodes[0].tagName == "TD")
                        {//this is for IE
                            tempComboID = rows[i].get_element().childNodes[1].childNodes[0].id;
                        }
                        else
                        {//this is in FF
                            tempComboID = rows[i].get_element().childNodes[2].childNodes[1].id;
                        }
                        if(tempComboID == comboID)
                        {
                            currentRow = rows[i];
                            nextRow = rows[i + 1];
                            break;
                        }
                    }
                    if(nextRow.get_element().childNodes[0].tagName == "TD")
                    {
                        nextComboID = nextRow.get_element().childNodes[1].childNodes[0].id;
                    }
                    else
                    {
                        nextComboID = nextRow.get_element().childNodes[2].childNodes[1].id;
                    }
                    $find(nextComboID).selectText();
                }
            }
            </script>
            </telerik:RadCodeBlock>
            <telerik:RadGrid ID="RadGrid1" runat="server" GridLines="None" OnNeedDataSource="RadGrid1_NeedDataSource"
                AllowMultiRowSelection="true" OnItemCreated="RadGrid1_ItemCreated">
                <MasterTableView AutoGenerateColumns="False" DataKeyNames="ID">
                    <Columns>
                        <telerik:GridBoundColumn DataField="ID" HeaderText="ID" UniqueName="ID">
                        </telerik:GridBoundColumn>
                        <telerik:GridTemplateColumn DataField="Name" HeaderText="Name" UniqueName="TemplateColumn">
                            <ItemTemplate>
                                <telerik:RadComboBox ID="RadComboBox1" runat="server" DataTextField="Name" 
                                    DataValueField="Name" SelectedValue='<%# Eval("Name") %>' AllowCustomText="true"
                                    OnClientKeyPressing="KeyPressing">
                                </telerik:RadComboBox>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridBoundColumn DataField="Name" HeaderText="Name" UniqueName="Name">
                        </telerik:GridBoundColumn>                        
                    </Columns>
                </MasterTableView>
                <ClientSettings>
                    <Selecting AllowRowSelect="True" />
                </ClientSettings>
            </telerik:RadGrid>
        </div>
    </form>
</body>
</html>
