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

[Solved] Linq FilterExpression

3 Answers 267 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rik
Top achievements
Rank 1
Rik asked on 15 Aug 2009, 07:02 AM
Hello,

I have a radgrid i want to filter with a custom template, i'm using a linq datasource but i get the following error: "Expression expected".
The property "EnableLinqExpressions" is false.
Here is my code:


aspx:
<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="LinqDataSource1"   
            AutoGenerateColumns="False" AllowAutomaticUpdates="True"   
            AutoGenerateEditColumn="True" GridLines="None" Skin="Forest" 
            AllowFilteringByColumn="True"  EnableLinqExpressions="False">  
            <MasterTableView cellspacing="-1"   
                        datasourceid="LinqDataSource1" datakeynames="Ge_ID" EditMode="PopUp">  
            <RowIndicatorColumn> 
            <HeaderStyle Width="20px"></HeaderStyle> 
            </RowIndicatorColumn> 
 
            <ExpandCollapseColumn> 
            <HeaderStyle Width="20px"></HeaderStyle> 
            </ExpandCollapseColumn> 
                <Columns> 
                    <telerik:GridBoundColumn DataField="GeEmail" HeaderText="GeEmail"   
                        SortExpression="GeEmail" UniqueName="GeEmail"   
                        CurrentFilterFunction="Contains" ShowFilterIcon="false"   
                        FilterListOptions="VaryByDataTypeAllowCustom">  
                        <FilterTemplate> 
                            <asp:TextBox runat="server" ID="FiltEmail"></asp:TextBox> 
                            <asp:Button runat="server" ID="BtnFilEmail" Text="Filter"  CommandArgument="Email" CommandName="Filter2" /> 
                        </FilterTemplate> 
                    </telerik:GridBoundColumn> 

 

 


Hier is CodeBehind(VB):

 

 Protected Sub RadGrid1_ItemCommand(ByVal source As ObjectByVal e As GridCommandEventArgs) Handles RadGrid1.ItemCommand  
        If e.CommandName = "Filter2" Then 
 
            Dim sField As String = e.CommandArgument.ToString  
 
            Select Case sField  
                Case "Email" 
                    Dim txt As TextBox = e.Item.FindControl("FiltEmail")  
                    Dim sVal As String = txt.Text.ToString  
 
                    RadGrid1.MasterTableView.FilterExpression = "([GeEmail] Like %'" & sVal & "'%)" 
 
                      
                    RadGrid1.Rebind()  
 
                    ' RadGrid1.MasterTableView.Rebind()  
 
                    Exit Select 
                Case Else 
                    Exit Select 
            End Select 
        End If 
    End Sub 
 


I even wan't to filter more colums.
I hope someone could help me.

 

 

 

 

 

 

3 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 17 Aug 2009, 08:12 AM
Hi Rik,

You can change this to:

 RadGrid1.MasterTableView.FilterExpression = "GeEmail.Contains(""" & sVal & """)"

Regards,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Rik
Top achievements
Rank 1
answered on 18 Aug 2009, 07:33 PM
Thx, this works great but i'm wondering why isn't my filterexpression not working,
and how can i filter filter a date?
For example:  "WHERE Date >= '8/18/2009' "

Thx so far for the great and fast support !!

 
0
Vlad
Telerik team
answered on 19 Aug 2009, 05:11 AM
Hi Rik,

Filter expressions are in two formats: SQL for .NET 2.0 and if EnableLinqExpressions is false and LINQ for .NET 3.5 and EnableLinqExpressions is set to true (default). Generally the grid LINQ expressions are almost exactly the same to the normal code (C#/VB.NET).

Sincerely yours,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Rik
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Rik
Top achievements
Rank 1
Share this question
or