<%@ Page Title="Home Page" Language="C#" AutoEventWireup="true"
    CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<!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>
    <title>ASP.NET Examples</title>
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
    <telerik:RadSkinManager ID="QsfSkinManager" runat="server" ShowChooser="true" />
    <telerik:RadFormDecorator ID="QsfFromDecorator" runat="server" DecoratedControls="All" EnableRoundedCorners="false" />
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadGrid1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1"></telerik:AjaxUpdatedControl>
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <br />
    <telerik:RadGrid ID="RadGrid1" DataSourceID="SqlDataSource1" GridLines="None" AllowPaging="True"
        AllowSorting="True" AutoGenerateColumns="false" AllowAutomaticDeletes="True"
        runat="server">
        <ClientSettings>
            <ClientEvents OnCommand="OnCommand" />
        </ClientSettings>
        <MasterTableView TableLayout="Fixed" DataKeyNames="OrderID,ProductID" ClientDataKeyNames="OrderID,ProductID">
            <Columns>
                <telerik:GridNumericColumn DataField="OrderID" HeaderText="OrderID">
                </telerik:GridNumericColumn>
                <telerik:GridNumericColumn DataField="ProductID" HeaderText="ProductID">
                </telerik:GridNumericColumn>
                <telerik:GridNumericColumn DataField="UnitPrice" HeaderText="UnitPrice" DataFormatString="{0:c}">
                </telerik:GridNumericColumn>
                <telerik:GridNumericColumn DataField="Quantity" HeaderText="Quantity">
                </telerik:GridNumericColumn>
                <telerik:GridNumericColumn DataField="Discount" HeaderText="Discount">
                </telerik:GridNumericColumn>
                <telerik:GridClientDeleteColumn ConfirmTextFields="OrderID" ConfirmTextFormatString="Are you sure you want to delete details for order {0}?"
                    HeaderStyle-Width="35px" ButtonType="ImageButton">
                </telerik:GridClientDeleteColumn>
            </Columns>
        </MasterTableView>
        <PagerStyle Mode="NextPrevAndNumeric"></PagerStyle>
    </telerik:RadGrid>
    <br />
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString35 %>"
        DeleteCommand="DELETE FROM [Order Details] WHERE [OrderID] = @OrderID AND [ProductID] = @ProductID"
        SelectCommand="SELECT * FROM [Order Details]">
        <DeleteParameters>
            <asp:Parameter Name="OrderID" Type="Int32"></asp:Parameter>
            <asp:Parameter Name="ProductID" Type="Int32"></asp:Parameter>
        </DeleteParameters>
    </asp:SqlDataSource>
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script type="text/javascript">
            function OnCommand(sender, args)
            {

                if (args.get_commandName() == "Delete")
                {
                    var itemIndex = args.get_commandArgument(),
                        dataItem = null,
                        dataItems = sender.get_masterTableView().get_dataItems();
                    for (var i = 0; i < dataItems.length; i++)
                    {
                        if (dataItems[i].get_itemIndexHierarchical() == itemIndex)
                        {
                            dataItem = dataItems[i];
                            break;
                        }
                    }                    
                    var history_id = dataItem.getDataKeyValue("ProductID");

                    args.set_cancel(true);
                }
            }       
        </script>
    </telerik:RadCodeBlock>
    </form>
</body>
</html>