<%@ 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 id="Head1" runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager runat="server" ID="ScriptManager1">
        </asp:ScriptManager>
        <telerik:RadAjaxManager runat="server" ID="RadAjaxManager1">
        </telerik:RadAjaxManager>
        <script type="text/javascript">
            function Command(sender, args)
            {
                if (sender._editIndexes.length > 0)
                {
                    var myCommandName = $get("<%=MyCommandName.ClientID %>");
                    switch (args.get_commandName())
                    {
                        case "Page": myCommandName.value = (confirm("The data is NOT saved and will be lost!\nDo you want to save it now?") == true ? "Page" : "Cancel"); break;
                        case "Edit": myCommandName.value = (confirm("The data is NOT saved and will be lost!\nDo you want to save it now?") == true ? "Edit" : "Cancel"); break;
                        default: myCommandName.value = "Cancel"; break;
                    }
                }
            }
        </script>
        <telerik:RadGrid ID="RadGrid1" runat="server" AllowAutomaticUpdates="True" AutoGenerateEditColumn="True"
            DataSourceID="SqlDataSource1" AllowPaging="True" PageSize="5" OnItemCommand="RadGrid1_ItemCommand"
            AllowMultiRowEdit="true" OnPreRender="RadGrid1_PreRender" 
            onitemcreated="RadGrid1_ItemCreated" OnDataBound="RadGrid1_DataBound" 
            onitemdatabound="RadGrid1_ItemDataBound">
            <MasterTableView AutoGenerateColumns="true" DataSourceID="SqlDataSource1" EditMode="EditForms">
            </MasterTableView>
            <ClientSettings>
                <ClientEvents OnCommand="Command" />
            </ClientSettings>
        </telerik:RadGrid>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
            SelectCommand="SELECT TOP 20 [CustomerID], [CompanyName], [ContactName], [Country] FROM [Customers]"
            UpdateCommand="UPDATE [Customers] SET [CompanyName] = @CompanyName, [ContactName] = @ContactName, [Country] = @Country WHERE [CustomerID] = @CustomerID">
        </asp:SqlDataSource>
        <asp:HiddenField runat="server" ID="MyCommandName" Value="" />
    </div>
    </form>
</body>
</html>
