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

Problem with FilterExpression in RadGrid

1 Answer 122 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Teija
Top achievements
Rank 1
Teija asked on 27 May 2010, 10:50 PM
Hi

Can somebody explain for me how the FilterExpression works?

Im trying to get a simple example to work as I want it to do.

In the example I first used a FilterExpression on the SQLDataSource. First taken from a dropdownlist and then explicitly as "Login_Name='Patrik'". In both cases the filtering is working fine.

Then Im trying to do the same with the RadGrids MasterTableViews FilterExpression but it doesnt seem to work the same. Or Im not getting the syntax. How would I write the FilterExpression to do the same for me as in the SQLDataSource?

And secondly how could I get the FilterExpression to take the selection in the DropDownList?

//Mathias

Here is my code: 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
 
<html xmlns="http://www.w3.org/1999/xhtml" > 
    <head id="Head1" runat="server"
    <title>ASP.NET Example</title> 
</head> 
<body> 
        <form id="form1" runat="server"
 
            <telerik:RadScriptManager runat="server"/> 
 
            <asp:DropDownList 
                id="DropDownList1" 
                runat="server" 
                AutoPostBack="True"
                <asp:ListItem Selected="True">Roland</asp:ListItem> 
                <asp:ListItem>Patrik</asp:ListItem> 
                <asp:ListItem>Petter</asp:ListItem> 
            </asp:DropDownList> 
 
            <asp:SqlDataSource 
                id="SqlDataSource1" 
                runat="server" 
                ConnectionString="???????" 
                SelectCommand="SELECT * FROM Sys_Users"
<%--                FilterExpression="Login_Name='Patrik'"
                <FilterParameters> 
                    <asp:ControlParameter Name="Title" ControlId="DropDownList1" PropertyName="SelectedValue"/> 
                </FilterParameters> 
--%>            </asp:SqlDataSource> 
 
            <p><telerik:RadGrid 
                id="GridView1" 
                runat="server" 
                DataSourceID="SqlDataSource1" 
                AutoGenerateColumns="False"
                <MasterTableView FilterExpression="([Login_Name]='Patrik')"
                    <Columns> 
                        <telerik:GridBoundColumn Visible="False" DataField="RecID" /> 
                        <telerik:GridBoundColumn HeaderText="First Name" DataField="F_Name" /> 
                        <telerik:GridBoundColumn HeaderText="Last Name" DataField="L_Name" /> 
                        <telerik:GridBoundColumn HeaderText="Login" DataField="Login_Name" /> 
                    </Columns> 
                </MasterTableView> 
            </telerik:RadGrid> 
 
        </form> 
    </body> 
</html> 

1 Answer, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 28 May 2010, 08:25 AM
Hello Mathias,

If you are using .net 3.5/4.0 version of RadGrid filter expressions are in different format. RadGrid internally use Dynamic LINQ in order to perform filtering. The format of the expression depends on what is the source that will be filtered.

In case of SqlDataSource format is as follow: it["FieldName"] = "Value". Thus the expressions like: Login_Name='Patrik' should look as follow: it["Login_Name"] = "Patrik".

Of course you can set EnableLinqExpressions to false of RadGrid and then use sql like expressions - same as for SqlDataSource.

Regards,
Nikolay
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
Teija
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Share this question
or