Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3855840
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:50:17+00:00 2026-05-19T17:50:17+00:00

I’m trying to implement a custom filter template for all text based searches and

  • 0

I’m trying to implement a custom filter template for all text based searches and running into problems constructing the query. I’ve been following the instructions posted on this blog but not sure how change the GetQueryable method to perform a

WHERE columnAttribute LIKE '%something%'

query. In the example on the blog the expression is an equality which works if the text I enter exactly matches the text in the database column.

At the moment I’m using the new QueryExtender feature along with the SearchExpression control but this requires creating several custom pages for all the tables I need text search functionality for. I would like to DRY this up by creating the custom filter template. Any help would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T17:50:18+00:00Added an answer on May 19, 2026 at 5:50 pm

    In LINQ to SQL, the Strings.Contains method is how you express the LIKE operator. What follows is an example of how you could build a filter template around the LIKE operator. For this example, we’ll give our custom filter template the name “Text”.

    The first step is to update the Dynamic Data metadata. Annotate all the columns you want to be able to search on with the FilterUIHintAttribute like so:

    [FilterUIHint("Text")]
    

    Now we need to create the “Text” filter template. Create the Text.ascx user control in the filter templates folder (typically “~/DynamicData/Filters”):

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Text.ascx.cs" Inherits="Text" %>
    
    <asp:TextBox runat="server" ID="TextBox1" autocomplete="off" OnTextChanged="TextBox1_Changed" />
    

    Next create the code behind, Text.ascx.cs:

    public partial class Text : QueryableFilterUserControl {
        public override Control FilterControl {
            get { return TextBox1; }
        }
    
        protected void TextBox1_Changed(object sender, EventArgs e) {
            OnFilterChanged();
        }
    
        public override IQueryable GetQueryable(IQueryable source) {
            var value = TextBox1.Text;
            if (String.IsNullOrWhiteSpace(value)) return source;
    
            if (DefaultValues != null) {
                DefaultValues[Column.Name] = value;
            }
    
            var parameter = Expression.Parameter(source.ElementType);
            var columnProperty = Expression.PropertyOrField(parameter, Column.Name);
            var likeValue = Expression.Constant(value, typeof (string));
            var condition = Expression.Call(
                columnProperty,
                typeof (string).GetMethod("Contains"),
                likeValue);
            var where = Expression.Call(
                typeof (Queryable),
                "Where",
                new[] { source.ElementType },
                source.Expression,
                Expression.Lambda(condition, parameter));
            return source.Provider.CreateQuery(where);
        }
    }
    

    Notice that we have provided no way for the user to postback the page (and hence, update the results) after updating the Text filter. As a matter of style, I find TextBox controls that auto-postback to be confusing, and I find that it is redundant to have a separate button to postback each individual filter. Instead, I like to add a single Button to the page template (for example, “~/DynamicData/PageTemplates/List.aspx”) that allows the user to postback the page and update the results. Here is the relevant excerpt:

    <asp:Panel runat="server" DefaultButton="UpdateFilter">
        <asp:QueryableFilterRepeater runat="server" ID="FilterRepeater">
            <ItemTemplate>
                <asp:Label runat="server" Text='<%# Eval("DisplayName") %>' OnPreRender="Label_PreRender" />
                <asp:DynamicFilter runat="server" ID="DynamicFilter" OnFilterChanged="DynamicFilter_FilterChanged" /><br />
            </ItemTemplate>
        </asp:QueryableFilterRepeater>
        <asp:Button runat="server" ID="UpdateFilter" Text="Search" />
    </asp:Panel>
    

    That’s all there is to it. Users should now be able to search for records that contain fragments of text in the specified columns.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.