Telerik is a leading vendor of ASP.NET AJAX, ASP.NET MVC, Silverlight, WinForms and WPF controls and components, as well as .NET Reporting, .NET ORM , .NET CMS, Code Analysis, Mocking, Team Productivity and Automated Testing Tools. Building on its expertise in interface development and Microsoft technologies, Telerik helps customers build applications with unparalleled richness, responsiveness and interactivity. Telerik products help thousands of companies to be more productive and deliver reliable applications under budget and on time.
select

Filter / Custom Field Editors




EmployeeIDLastNameFirstNameCountryHomePhone
     
12
Page size:
select
 10 items in 2 pages
1AvilonNancyUSA (206) 555-9857
2LeverlingJanetUSA (206) 555-9482
3PeacockMargaretUSA (206) 555-3412
4BuchananStevenUSA (206) 555-8122
5SuyamaMichaelUK (71) 555-4848

  • This demo illustrates how to create and use custom field editors - with RadComboBox and RadMaskedTextBox in particular.
    Also, it shows various other RadFilter features: adding field editors and filter expressions dynamically, building filter expressions manually and reducing filter menu options.

Source Code

C# VB.NET
Show code in new window Demo isolation steps
  • <%@ Page Language="C#" AutoEventWireup="true" CodeFile="DefaultCS.aspx.cs" Inherits="Telerik.FilterExamplesCSharp.CustomEditors.DefaultCS" %>

    <%@ Register TagPrefix="telerik" Namespace="Telerik.QuickStart" %>
    <%@ Register TagPrefix="qsf" Namespace="Telerik.QuickStart" %>
    <%@ Register TagPrefix="telerik" TagName="Header" Src="~/Common/Header.ascx" %>
    <%@ Register TagPrefix="telerik" TagName="HeadTag" Src="~/Common/HeadTag.ascx" %>
    <%@ Register TagPrefix="telerik" TagName="Footer" Src="~/Common/Footer.ascx" %>
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <%@ Register Namespace="FilterCustomEditors" TagPrefix="custom" %>
    <!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">
        <telerik:HeadTag runat="server" ID="Headtag2" />
        <title></title>
    </head>
    <body class="BODY">
        <form runat="server" id="mainForm" method="post">
        <div>
            <telerik:Header runat="server" ID="Header1" NavigationLanguage="CS" ShowSkinChooser="true" />
            <!-- content start -->
            <telerik:RadScriptManager ID="RadScriptManager1" runat="server" />
            <telerik:RadAjaxLoadingPanel runat="server" ID="RadAjaxLoadingPanel1" />
            <telerik:RadAjaxPanel runat="server" ID="RadAjaxPanel1" EnableAJAX="true" LoadingPanelID="RadAjaxLoadingPanel1">
                <div>
                    <telerik:RadFilter runat="server" ID="RadFilter1" OnFieldEditorCreating="RadFilter1_FieldEditorCreating"
                        ExpressionPreviewPosition="Bottom" OnApplyExpressions="RadFilter1_ApplyExpressions">
                        <FieldEditors>
                            <telerik:RadFilterNumericFieldEditor FieldName="EmployeeID" DataType="System.Int32" />
                            <telerik:RadFilterTextFieldEditor FieldName="LastName" />
                            <custom:RadFilterMaskedTextBoxEditor FieldName="HomePhone" Mask="(###) ###-####"
                                DisplayMask="(###) ###-####" DisplayPromptChar="_" PromptChar="#" />
                        </FieldEditors>
                    </telerik:RadFilter>
                </div>
                <br />
                <br />
                <br />
                <div>
                    <telerik:RadGrid ID="RadGrid1" AllowPaging="True" ShowFooter="True" runat="server"
                        EnableLinqExpressions="false" PagerStyle-AlwaysVisible="true" AutoGenerateColumns="False"
                        PageSize="5" GridLines="None" OnNeedDataSource="RadGrid1_NeedDataSource">
                        <MasterTableView>
                            <Columns>
                                <telerik:GridBoundColumn DataField="EmployeeID" DataType="System.Int32" HeaderText="EmployeeID"
                                    SortExpression="EmployeeID" UniqueName="EmployeeID">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="LastName" HeaderText="LastName" SortExpression="LastName"
                                    UniqueName="LastName">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="FirstName" HeaderText="FirstName" SortExpression="FirstName"
                                    UniqueName="FirstName">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="Country" HeaderText="Country" SortExpression="Country"
                                    UniqueName="Country">
                                </telerik:GridBoundColumn>
                                <telerik:GridTemplateColumn DataField="HomePhone" HeaderText="HomePhone" SortExpression="HomePhone"
                                    UniqueName="HomePhone">
                                    <ItemTemplate>
                                        <%# string.Format("{0:(###) ###-####}", Convert.ToInt64(Eval("HomePhone")))%>
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>
                            </Columns>
                        </MasterTableView>
                    </telerik:RadGrid>
                </div>
            </telerik:RadAjaxPanel>
            <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
                <script type="text/javascript">
                    function pageLoad() {
                        var filter = $find("<%=RadFilter1.ClientID %>");
                        var menu = filter.get_contextMenu();
                        menu.add_showing(FilterMenuShowing);
                    }

                    function FilterMenuShowing(sender, args) {
                        var filter = $find("<%=RadFilter1.ClientID %>");
                        var currentExpandedItem = sender.get_attributes()._data.ItemHierarchyIndex;
                        var fieldName = filter._expressionItems[currentExpandedItem];
                        var allFields = filter._dataFields;
                        if (fieldName == "Country") {
                            for (var i = 0, j = allFields.length; i < j; i++) {
                                if (allFields[i].FieldName == fieldName) {
                                    sender.findItemByValue("StartsWith").set_visible(false);
                                    sender.findItemByValue("EndsWith").set_visible(false);
                                    sender.findItemByValue("GreaterThan").set_visible(false);
                                    sender.findItemByValue("GreaterThanOrEqualTo").set_visible(false);
                                    sender.findItemByValue("LessThan").set_visible(false);
                                    sender.findItemByValue("LessThanOrEqualTo").set_visible(false);
                                    sender.findItemByValue("Contains").set_visible(false);
                                    sender.findItemByValue("DoesNotContain").set_visible(false);
                                    sender.findItemByValue("Between").set_visible(false);
                                    sender.findItemByValue("NotBetween").set_visible(false);
                                }
                            }
                        }
                    }
                </script>
            </telerik:RadCodeBlock>
            <!-- content end -->
            <telerik:Footer runat="server" ID="Footer1"></telerik:Footer>
        </div>
        </form>
    </body>
    </html>

Get more than expected!

 
 

Take your time to truly experience the power of RadControls for ASP.NET AJAX with a free 60-day trial backed up by Telerik’s unlimited dedicated support.

Download your RadControls for ASP.NET AJAX trial and jumpstart your development with the available Getting Started resources.

If you have any questions, do not hesitate to contact us at sales@telerik.com.

Copyright 2002-2024 © Telerik. All right reserved
Telerik Inc, 201 Jones Rd, Waltham, MA 02451