This is a migrated thread and some comments may be shown as answers.

RadGrid > Setting the FilterExpression to a Column Programmatically > Apostrophe symbol (‘) doesn’t work

8 Answers 364 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mikel
Top achievements
Rank 1
Mikel asked on 08 Jan 2010, 05:02 PM

Hi everybody

We are having a funny trouble when passing strings with apostrophe to our Telerik RadGrid's Filters. Here goes the scenario:

We have a Grid with a column called "RoomName" that shows a RadComboBox with different rooms (binded from the DB)

We want toset our telerik grids FilterExpression programmatically (on PAGE_LOAD time) with the following code. 

RadGrid1.AllowFilteringByColumn= true;

RadGrid1.MasterTableView.FilterExpression = string.Format("([RoomName]= '{0}')", VALUE);


This code works fineexcept when the VALUE contains an apostrophe. i.e: “Mikel’s Room”

In this case, the filter won't work and the grid will load all the Campaigns (without filtering)

Is thereany documented bug on this?

8 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 13 Jan 2010, 08:50 AM
Hello Mikel,

My colleague Yavor already responded in the support ticket you opened in connection to this subject. To avoid duplicate posts, please continue the communication there if you do not mind.

Greetings,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Alf Stevens
Top achievements
Rank 1
answered on 15 Apr 2010, 05:01 AM
So whats the solution , I am also experiencing this problem.

Thanks

Alf
0
Pavlina
Telerik team
answered on 15 Apr 2010, 12:50 PM
Hi Alf,

To achieve the desired functionality you will need to make sure that the filter expression does not contain the " ' " symbol. Or, if it does, that it is escaped properly. For example, entering ['] instead of a single apostrophe.
Give this approach a try and let me know how it goes.

Kind regards,
Pavlina
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Alf Stevens
Top achievements
Rank 1
answered on 16 Apr 2010, 02:10 AM
Hi Pavlina,

Im not sure how to implement. I have simply enabled the filters at the moment on the RadGrid control and the users keys into the filter , for example the customers surname.

If they key in O'Donnel and Select "EqualTo" on the filter then nothing will appear. How do I get to override the entered text to apply the filter.

I tried using the ItemCommand event to replace the apostraphe..
....
            Pair FilterPair = (Pair)e.CommandArgument;
            String ColName = FilterPair.Second.ToString();
            TextBox TBPattern = (e.Item as GridFilteringItem)[ColName].Controls[0] as TextBox;
            String NewFilter = FilterPair.First.ToString() + " = " + TBPattern.Text.ToString().Replace("'", "''");
            RadGrid1.MasterTableView.FilterExpression = NewFilter;
            RadGrid1.Rebind();
......

But I get the exception

No property or field 'CustomerSurname' exists in type 'DataRowView'

I take it this is because the Radgrid has not got the datasource , so I must be putting the logic in the wrong place , I just need help on exactly where I need to do this and if Im taking the correct approach.

Many Thanks

Alf
0
Pavlina
Telerik team
answered on 16 Apr 2010, 03:57 PM
Hello Alf,

I am sending you a sample page that shows how to do this. Please, give it a try and let me know if other questions or problems arise.

Kind regards,
Pavlina
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Alf Stevens
Top achievements
Rank 1
answered on 19 Apr 2010, 03:48 AM
Hi Pavlina,

I have updated the RadGrid controls and it has started working , Im not sure why or how as I was using the latest version anyway. Its working so I guess ill stay away from it.

Thanks for you example but I couldnt really use it as it was mising the Object Datasource for the types it uses TypeName="DataSources.CampaignDS". I understand about messing with the filtering of the radgrid so if this problem does come back I will then try and make alterations... but at the moment whilst its working Im not going to touch it :).

Many Thanks

Alf
0
James
Top achievements
Rank 1
answered on 25 Jun 2010, 05:10 PM
We are experiencing this issue with version 200931.402.35 of the controls, filtering works when we run a contains filter on \' but throws an error when we search on a single apostrophe still, suggesting that the single apostrophe is still not being escaped?

We have also tried this in one of our .NET 4 projects using the latest version of the dll (2010.1.519) and the filtering does not throw a javascript error but still does not work.

Thanks,
James Hollyhomes
0
Pavlina
Telerik team
answered on 30 Jun 2010, 04:10 PM
Hi James,

Could you, please open a formal support ticket and send a test project, demonstrating your setup, and showing the unwanted behavior. We will debug it locally, and get back to you with more information on the matter.

Thank you!

Best wishes,
Pavlina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Mikel
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Alf Stevens
Top achievements
Rank 1
James
Top achievements
Rank 1
Share this question
or