<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="Telerik.Web.UI"  Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<!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" />
        <div>
                        
            
            <script type="text/javascript">
                function ItemSelected(source, eventArgs)
                {                    
                    source.get_element().value = eventArgs.get_value();
                }
            </script>
            
            <telerik:RadGrid runat="server" ID="RadGrid1" AutoGenerateColumns="False" 
                DataSourceID="SqlDataSource1" GridLines="None" AllowAutomaticDeletes="True"
                AllowAutomaticInserts="True" AllowAutomaticUpdates="True" AllowPaging="True">
                <MasterTableView DataSourceID="SqlDataSource1" CommandItemDisplay="Top" DataKeyNames="CustomerID">
                    <Columns>
                        <telerik:GridTemplateColumn UniqueName="TemplateColumn" DataField="CustomerID" 
                            HeaderText="CustomerID">
                            <ItemTemplate> 
                                <asp:Label runat="server" ID="Label1" Text='<%#Eval("CustomerID") %>'></asp:Label>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:TextBox runat="server" ID="TextBox1" Text='<%#Bind("CustomerID") %>'>
                                </asp:TextBox>
                                <ajaxToolkit:AutoCompleteExtender runat="server" ID="AutoCompleteExtender1"
                                    TargetControlID="TextBox1" 
                                    ServiceMethod="GetCompletionListOfCustomers"
                                    ServicePath="AutoComplete.asmx"
                                    MinimumPrefixLength="2" 
                                    CompletionInterval="0"                
                                    CompletionSetCount="20"
                                    OnClientItemSelected="ItemSelected">
                                </ajaxToolkit:AutoCompleteExtender>
                            </EditItemTemplate>
                        </telerik:GridTemplateColumn>
                        
                        <telerik:GridBoundColumn DataField="CompanyName" 
                            HeaderText="CompanyName" UniqueName="CompanyName">
                        </telerik:GridBoundColumn>
                        
                        <telerik:GridBoundColumn DataField="ContactName" 
                            HeaderText="ContactName" UniqueName="ContactName">
                        </telerik:GridBoundColumn>
                        
                        <telerik:GridEditCommandColumn>
                        </telerik:GridEditCommandColumn>
                    </Columns>                   
                    <RowIndicatorColumn>
                        <HeaderStyle Width="20px" />
                    </RowIndicatorColumn>
                    <ExpandCollapseColumn>
                        <HeaderStyle Width="20px" />
                    </ExpandCollapseColumn>
                    <EditFormSettings>
                        <EditColumn UniqueName="EditCommandColumn1">
                        </EditColumn>
                    </EditFormSettings>
                </MasterTableView>                
                <FilterMenu EnableTheming="True">
                    <CollapseAnimation Duration="200" Type="OutQuint" />
                </FilterMenu>
            </telerik:RadGrid>
            
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
                DeleteCommand="DELETE FROM [Customers] WHERE [CustomerID] = @CustomerID" 
                InsertCommand="INSERT INTO [Customers] ([CustomerID], [CompanyName], [ContactName]) VALUES (@CustomerID, @CompanyName, @ContactName)"
                SelectCommand="SELECT [CustomerID], [CompanyName], [ContactName] FROM [Customers]"
                UpdateCommand="UPDATE [Customers] SET [CompanyName] = @CompanyName, [ContactName] = @ContactName WHERE [CustomerID] = @CustomerID">
                <DeleteParameters>
                    <asp:Parameter Name="CustomerID" Type="String" />
                </DeleteParameters>
                <UpdateParameters>
                    <asp:Parameter Name="CompanyName" Type="String" />
                    <asp:Parameter Name="ContactName" Type="String" />
                    <asp:Parameter Name="CustomerID" Type="String" />
                </UpdateParameters>
                <InsertParameters>
                    <asp:Parameter Name="CustomerID" Type="String" />
                    <asp:Parameter Name="CompanyName" Type="String" />
                    <asp:Parameter Name="ContactName" Type="String" />
                </InsertParameters>
            </asp:SqlDataSource>
            
           
            
        </div>
    </form>
</body>
</html>
