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 about 1 year ago.




# Comment from

4 months 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 88 Sml_a33

Clear, 80

80
69
More Weather
What's New
Ban Water! It is Dangerous! A Visual Guide to Inflation Avatar to be Released Tomorrow My Favorite Two Line Phone Pranks Paul's Top 15 Fiction Novels
Last Blog (2009-03-28)
"Finally! I'm on Twitter!: It took me long enough. :) ..."
Popular Pages
What's New Deep Thoughts by Jack Handey Invoke Updates the Parent Form From Child Thread Get Rid of Cable With TiVo and a Converter Box Chuck Norris Facts
Deep Thought
I wish I would have a real tragic love affair and get so bummed out that I'd just quit my job and become a bum for a few years, because I was thinking about doing that anyway.
Sponsored Links

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