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

Like Search

1 Answer 61 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Punit
Top achievements
Rank 1
Punit asked on 26 Dec 2008, 11:30 AM

Posted on Dec 3 (permalink)

Hi

We are implemting grid filtering by giving filter expression in Need_DataSource event by setting following property -

Grid.MasterTableView.FilterExpression

which is set to something like the following

DataSourceProperty.ToString().ToUpper().StartsWith("Hi")  where DataSourceProperty is a property of object, collection of which is set as Data Source to the grid just after setting filter expressio.

Now my problem is that we wnat to give a user option to put % in the filter values and the filter should work like "Like" opertor in Oracle. So the input may be "punit%was%" .

For this I have tried to set the property like below as suggested in documenattion at some place :-
RadGrid1.MasterTableView.FilterExpression =
"([Country] LIKE \'%Germany%\') ";
 
Along with this I have also set  grid LINQ expressions to false (EnableLinqExpressions=false) .

But this is not actually filtering the results and is just returning the results without filtering.


Thanks

1 Answer, 1 is accepted

Sort by
0
Kevin Babcock
Top achievements
Rank 1
answered on 28 Dec 2008, 02:05 PM
Hi Punit,

I am able to successfully filter the contents of the RadGrid using the FilterExpression property demonstrated in this demo. Here is a simple example I created using the Northwind database:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Telerik.Examples._Default" %> 
 
<%@ 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 runat="server"
    <title>Example</title> 
</head> 
<body> 
    <form id="form1" runat="server"
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server" /> 
         
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"
            <AjaxSettings> 
                <telerik:AjaxSetting AjaxControlID="RadGrid1"
                    <UpdatedControls> 
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1"  
                            LoadingPanelID="RadAjaxLoadingPanel1" /> 
                    </UpdatedControls> 
                </telerik:AjaxSetting> 
            </AjaxSettings> 
        </telerik:RadAjaxManager> 
         
        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server"
            <img alt="Loading..."  
                src='<%= RadAjaxLoadingPanel.GetWebResourceUrl(Page, "Telerik.Web.UI.Skins.Default.Ajax.LoadingProgressBar.gif") %>' 
                style="margin-top: 100px;" /> 
        </telerik:RadAjaxLoadingPanel> 
         
        <telerik:RadGrid ID="RadGrid1" runat="server" 
            AllowFilteringByColumn="true" 
            AllowPaging="true" 
            AllowSorting="true" 
            AutoGenerateColumns="false" 
            DataSourceID="SqlDataSource1" 
            EnableLinqExpressions="false" 
            PageSize="10"
            <MasterTableView FilterExpression="([ProductName] LIKE '%Anton%')"
                <Columns> 
                    <telerik:GridBoundColumn 
                        CurrentFilterFunction="NoFilter" 
                        DataField="ProductName" 
                        HeaderText="Product"
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn 
                        CurrentFilterFunction="NoFilter" 
                        DataField="CategoryID" 
                        HeaderText="CategoryID"
                    </telerik:GridBoundColumn> 
                    <telerik:GridNumericColumn 
                        CurrentFilterFunction="NoFilter" 
                        DataField="UnitPrice" 
                        DataFormatString="{0:c}" 
                        HeaderText="Price">                      
                    </telerik:GridNumericColumn> 
                    <telerik:GridNumericColumn 
                        CurrentFilterFunction="NoFilter" 
                        DataField="UnitsInStock" 
                        HeaderText="Units"
                    </telerik:GridNumericColumn> 
                </Columns> 
            </MasterTableView> 
        </telerik:RadGrid>       
         
        <asp:SqlDataSource ID="SqlDataSource1" runat="server"  
            ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"  
            SelectCommand="SELECT * FROM [Products]"
        </asp:SqlDataSource> 
    </form> 
</body> 
</html> 
 


I hope this helps. If you continue to have trouble let me know and I'd be glad to help you further.

Regards,
Kevin Babcock
Tags
Grid
Asked by
Punit
Top achievements
Rank 1
Answers by
Kevin Babcock
Top achievements
Rank 1
Share this question
or