Like Search

2 posts, 0 answers
  1. Punit
    Punit avatar
    12 posts
    Member since:
    Sep 2008

    Posted 26 Dec 2008 Link to this post

    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

  2. Kevin Babcock
    Kevin Babcock avatar
    189 posts
    Member since:
    Mar 2007

    Posted 28 Dec 2008 Link to this post

    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
Back to Top