Header My Outline
Clear Back

Making Telerik RadGrid Filter Case Insensitive

I recently created a Telerik RadGrid (which is an AWESOME control, by the way) that listed all the states in the USA. The list is big, especially when we list all the territories in the USA, like Puerto Rico, American Samoa, etc. I wanted to filter my results.

No filter applied

Figure 1: No filters applied. With all the states returned, it can be frustrating to find the state or territory you are interested in.

There are two ways to make your Telerik RadGrid case insensitive. The first way is in your code-behind. The other way is by changing your form’s markup.

Method 1: In Code

/// <summary>
/// Handles the Load event of the Page control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.EventArgs"/></param>
protected void Page_Load(object sender, EventArgs e)
{
StateAdjustmentGrid.GroupingSettings.CaseSensitive = false;
}

In the Page_Load() event you put something in there like this:

This method works well enough, but I don’t like formatting settings applied in code. It is awkward and can lead to confusion. That’s why I prefer method 2.

Filtered with a case sensitive state

Figure 2: Filter Applied. “Neb” does return “Nebraska” which is great—but this is case-sensitive.

Filtered with a case sensitive state--no results

Figure 3: Filter Applied. “neb” does not return any states because it is case-sensitive.

Method 2: In Markup

In your markup for your grid you can put the following line:

<telerik:RadGrid ID="StateAdjustmentGrid" runat="server" 
AutoGenerateColumns="False" GridLines="None" Skin="Office2007"
AllowFilteringByColumn="False" AllowPaging="True" AllowSorting="True"
PageSize="20" Width="500px"
onneeddatasource="StateAdjustmentGrid_NeedDataSource"
oninsertcommand="StateAdjustmentGrid_InsertCommand"
onitemcommand="StateAdjustmentGrid_ItemCommand"
onitemcreated="StateAdjustmentGrid_ItemCreated"
>
<GroupingSettings CaseSensitive="false" />

The important line is the GroupingSettings line (the other code can be ignored as it was just shown to give you context).

I prefer this method because it doesn’t require a recompile and it “fits” better with the rest of your markup. That is, when I want to see all the settings and formatting requirements I like to look at the markup first. The settings applied in the code-behind are more sinister and hidden.

Correct Filtering

Figure 4: Filter Applied. “neb” does return “Nebraska” because it doesn’t care about your case. SUCCESS!

Last modified about over 2 years ago.




# Comment from

about 1 year ago.   

Really useful! Thanks.



Barry
# Comment from

almost 2 years ago.   

Thanks! it's worked!

You May Also Like...

  • Invoke Updates the Parent Form From Child Thread
    In my multi-threaded application I was getting errors about updating the parent form on the thread that is running it. Here is an easy way to make your .NET Windows Form application thread-safe.
Omaha Weather
Click to Enlarge 35 Sml_a07

Cloudy, 30

30
19
More Weather
What's New
My Band Get Rid of Cable With TiVo and a Converter Box Chernobyl 1986 vs. Fukushima Japan Radiation Best Charlie Sheen Quotes: Winning! Tiger Blood Stop Fighting (Cartoon by David Malki)
Last Blog (2009-03-28)
"Finally! I'm on Twitter!: It took me long enough. :) ..."
Popular Pages
Deep Thoughts by Jack Handey Get Rid of Cable With TiVo and a Converter Box Invoke Updates the Parent Form From Child Thread What's New FreeBSD Partition Types
Deep Thought
When I think of all the hours and hours of my life I have spent watching television, it makes me realize, Man, I am really rich with television.
Sponsored Links

All content © 1997-2010 . All Rights Reserved. Privacy Policy