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

Error When setting filter in code behind

4 Answers 167 Views
Grid
This is a migrated thread and some comments may be shown as answers.
SonicImaging
Top achievements
Rank 1
SonicImaging asked on 12 Nov 2008, 03:33 PM
Hi,  I have a link in my CommandItemtemplate that I want to hide records that have a value set to false when clicked on

In my onItemCommand I have a command hideVersions as follows

 if (e.CommandName == "hideVersions")
     {
         RG1.MasterTableView.FilterExpression = "([active]=0) ";
         GridColumn column = RG1.MasterTableView.GetColumnSafe("active");
         column.CurrentFilterFunction = GridKnownFunction.EqualTo;
         RG1.MasterTableView.Rebind();
         return;
     }

The column unique name is "active" and allow filtering is set to true for this column but I need to have AllowFilteringByColumn="false" since I don't want the user to be able to change the filtering. ( i tried it both ways)  The database field is a boolean.   I tried another text field and anything I put in the FilterExpression gives me the same error.   I also tried setting EnableLinqExpressions="false" since im using linq.

when I click the link I get the following error
System.Web.Query.Dynamic.ParseException: Expression expected at RG1.MasterTableView.Rebind();

Any Thoughts?
-Keith

4 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 12 Nov 2008, 03:45 PM
Hello Keith,

You can hide the filtering items as shown on the following demo:
Filtering demo

Let us know whether this approach suits your scenario.

Regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
SonicImaging
Top achievements
Rank 1
answered on 12 Nov 2008, 04:03 PM
yea I tried that also, but it doesn't seem to matter if I have the filters showing at the top.  I still end up with the error when I try to set the filter myself

What i have is simple versioning and each record has a boolean active field that is either true or false,  if its true its the current version and if its false its a past version.  So there will always only be one version active and the rest will be false.

So normally i want the grid to only show the current versions when active is set to true, then if the user wants to work on the past versions they click the show version link and it shows all the versions,  when all versions are showing I have a revert link instead of a edit link that will set all the other versions to false and the one they clicked on to true.

when the filters are showing at the top I can change the filtering manually and that works but its when I try to set the filter myself is when I get that error

Thanks
-Keith


0
SonicImaging
Top achievements
Rank 1
answered on 12 Nov 2008, 04:57 PM
I figured out a work around instead of having to use the filtering in radgrid,  I set the Where parameters in onselecting for my linq datasource based on a user selection to show or hide the versions and that works fine.

id still like to find out why I cant set the filtering without that error.  currently I can only set the filtering using the filtering in radgrid and not from code.

Thanks
-Keith
0
Accepted
Daniel
Telerik team
answered on 17 Nov 2008, 12:58 PM
Hello Keith,

For your convenience I created a simple demo website illustrating the requested functionality. Check whether it works as expected at your side.

Regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
SonicImaging
Top achievements
Rank 1
Answers by
Daniel
Telerik team
SonicImaging
Top achievements
Rank 1
Share this question
or