<%@ Page Language="C#" AutoEventWireup="true" CodeFile="GridFiltering.aspx.cs" Inherits="Default5" Culture="nl-NL" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<!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" lang="en">
<head runat="server">
    <title></title>

</head>
<body>
    <form id="form1" runat="server">
        <telerik:RadScriptManager runat="server" ID="Rsm1">
        </telerik:RadScriptManager>
        <telerik:RadCodeBlock runat="server">
                <script type="text/javascript">
                    function clearFilter() {

            var grid = $find("<%=RadGrid1.ClientID %>");
            var filterExpression = new Telerik.Web.UI.GridFilterExpression();
            var filterFunction = Telerik.Web.UI.GridFilterFunction.EqualTo;
            filterExpression.set_fieldName("UnitPrice");
            filterExpression.set_fieldValue("");
            filterExpression.set_filterFunction(filterFunction);
            filterExpression.set_columnUniqueName("UnitPrice");
            grid.get_masterTableView()._updateFilterControlValue("", "UnitPrice", filterFunction);
            grid.get_masterTableView()._filterExpressions.clear();
            grid.get_masterTableView()._filterExpressions.add(filterExpression);
            grid.get_masterTableView().set_pageSize(10);
           // grid.get_masterTableView().rebind();

        }

    </script>
        </telerik:RadCodeBlock>
        <telerik:RadGrid AllowSorting="true" MasterTableView-AllowFilteringByColumn="true"  ID="RadGrid1" runat="server"  AutoGenerateColumns="False"  AllowPaging="true" 
            AutoGenerateDeleteColumn="True"   EnableHeaderContextMenu="true" EnableHeaderContextFilterMenu="true"  AutoGenerateEditColumn="True" AllowFilteringByColumn="true"
            DataSourceID="SqlDataSource1">
            <MasterTableView DataKeyNames="ProductID" DataSourceID="SqlDataSource1" EditMode="PopUp" ShowFooter="true" >
                <Columns>
                    <telerik:GridBoundColumn DataField="UnitPrice" Aggregate="First"
                        FilterControlAltText="Filter UnitPrice column" HeaderText="UnitPrice"
                        SortExpression="UnitPrice" UniqueName="UnitPrice">
                    </telerik:GridBoundColumn>
                        <telerik:GridCalculatedColumn HeaderText="Total Price" UniqueName="TotalPrice" DataType="System.Double"
                    DataFields="UnitPrice" Expression="{0}*2" FooterText="Total : "
                    Aggregate="Sum">
                </telerik:GridCalculatedColumn>
                </Columns>
            </MasterTableView>
               <ClientSettings AllowDragToGroup="true" AllowColumnsReorder="true">
                   <Scrolling AllowScroll="true" UseStaticHeaders="true" />
               </ClientSettings>
        </telerik:RadGrid>
        <telerik:RadButton runat="server" ID="btn1" AutoPostBack="false" OnClientClicked="clearFilter" Text="Clear"></telerik:RadButton>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
        DeleteCommand="DELETE FROM [Products] WHERE [ProductID] = @ProductID" InsertCommand="INSERT INTO [Products] ([ProductName], [CategoryID], [UnitPrice], [Discontinued], [QuantityPerUnit], [UnitsInStock]) VALUES (@ProductName, @CategoryID, @UnitPrice, @Discontinued, @QuantityPerUnit, @UnitsInStock)"
        SelectCommand="SELECT [ProductID], [ProductName], [CategoryID], [UnitPrice], [Discontinued], [QuantityPerUnit], [UnitsInStock] FROM [Products] WITH(NOLOCK)"
        UpdateCommand="UPDATE [Products] SET [ProductName] = @ProductName, [CategoryID] = @CategoryID, [UnitPrice] = @UnitPrice, [Discontinued] = @Discontinued, [QuantityPerUnit] = @QuantityPerUnit, [UnitsInStock] = @UnitsInStock WHERE [ProductID] = @ProductID">
        <DeleteParameters>
            <asp:Parameter Name="ProductID" Type="Int32"></asp:Parameter>
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="ProductName" Type="String"></asp:Parameter>
            <asp:Parameter Name="CategoryID" Type="Int32"></asp:Parameter>
            <asp:Parameter Name="UnitPrice" Type="Decimal"></asp:Parameter>
            <asp:Parameter Name="Discontinued" Type="Boolean"></asp:Parameter>
            <asp:Parameter Name="QuantityPerUnit" Type="String"></asp:Parameter>
            <asp:Parameter Name="UnitsInStock" Type="Int16"></asp:Parameter>
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="ProductName" Type="String"></asp:Parameter>
            <asp:Parameter Name="CategoryID" Type="Int32"></asp:Parameter>
            <asp:Parameter Name="UnitPrice" Type="Decimal"></asp:Parameter>
            <asp:Parameter Name="Discontinued" Type="Boolean"></asp:Parameter>
            <asp:Parameter Name="QuantityPerUnit" Type="String"></asp:Parameter>
            <asp:Parameter Name="UnitsInStock" Type="Int16"></asp:Parameter>
            <asp:Parameter Name="ProductID" Type="Int32"></asp:Parameter>
        </UpdateParameters>
    </asp:SqlDataSource>
    </form>
</body>
</html>
