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

[Solved] Filtering problems

6 Answers 119 Views
Grid
This is a migrated thread and some comments may be shown as answers.
tom cat
Top achievements
Rank 1
tom cat asked on 21 Feb 2010, 05:58 PM
I'm using Telerik Radcontrol and I have some problems with radgrid filtering controls. I want to use a dropdownlist control insted of a textfield and a filter image button. But my code doesn't work. Here my code, please help me:
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="tryFilter._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></title
</head> 
<body> 
    <form id="form1" runat="server"
    <div> 
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server"
        </telerik:RadScriptManager> 
    
     
        <telerik:RadGrid ID="RadGrid1" runat="server" AllowFilteringByColumn="True"  
            AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False"  
            DataSourceID="SqlDataSource1" GridLines="None" Skin="Outlook"
<MasterTableView cellspacing="-1" datakeynames="ProductID" datasourceid="SqlDataSource1"
<RowIndicatorColumn> 
<HeaderStyle Width="20px"></HeaderStyle> 
</RowIndicatorColumn> 
 
<ExpandCollapseColumn> 
<HeaderStyle Width="20px"></HeaderStyle> 
</ExpandCollapseColumn> 
    <Columns> 
        <telerik:GridBoundColumn DataField="ProductName" HeaderText="ProductName"  
            SortExpression="ProductName" UniqueName="ProductName"
        </telerik:GridBoundColumn> 
        <telerik:GridBoundColumn DataField="UnitsOnOrder" DataType="System.Int16"  
            HeaderText="UnitsOnOrder" SortExpression="UnitsOnOrder"  
            UniqueName="UnitsOnOrder"
        </telerik:GridBoundColumn> 
        <telerik:GridTemplateColumn DataField="Discontinued" HeaderText="Discontinued"  
            UniqueName="column"
            <EditItemTemplate> 
                <asp:TextBox ID="DiscontinuedTextBox" runat="server"  
                    Text='<%# Bind("Discontinued") %>'></asp:TextBox> 
            </EditItemTemplate> 
            <ItemTemplate> 
                <asp:Label ID="DiscontinuedLabel" runat="server"  
                    Text='<%# Eval("Discontinued") %>'></asp:Label> 
            </ItemTemplate> 
            <FilterTemplate> 
                <asp:DropDownList ID="cbbDiscontinued" AutoPostBack="true"  
                        OnSelectedIndexChanged="cbbDiscontinued_SelectedIndexChanged" runat="server"
                    <asp:ListItem Text="All" Value="-1"></asp:ListItem> 
                    <asp:ListItem Text="Active" Value="1"></asp:ListItem> 
                    <asp:ListItem Text="Lock" Value="0"></asp:ListItem> 
                </asp:DropDownList> 
            </FilterTemplate> 
        </telerik:GridTemplateColumn> 
    </Columns> 
</MasterTableView> 
        </telerik:RadGrid> 
        <asp:SqlDataSource ID="SqlDataSource1" runat="server"  
            ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"  
            SelectCommand="SELECT * FROM [Products]"
        </asp:SqlDataSource> 
    
     
    </div> 
    </form> 
</body> 
</html> 
 
Default.aspx.cs
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using Telerik.Web; 
using Telerik.Web.UI; 
 
namespace tryFilter 
    public partial class _Default : System.Web.UI.Page 
    { 
        protected void Page_Load(object sender, EventArgs e) 
        { 
 
        } 
 
        protected void cbbDiscontinued_SelectedIndexChanged(object sender, EventArgs e) 
        { 
            DropDownList cbbDiscontinued=(DropDownList)sender; 
            this.RadGrid1.Columns[2].CurrentFilterValue = cbbDiscontinued.SelectedValue; 
            this.RadGrid1.Columns[2].CurrentFilterFunction = GridKnownFunction.EqualTo; 
            this.RadGrid1.Rebind(); 
        } 
    } 
 

6 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 22 Feb 2010, 07:21 AM
Hi,

You need to set the FilterExpression for the RadGrid in the DropDownList SelectedIndexChanged event as shown below:

 protected void cbbCategoryName_SelectedIndexChanged(object sender, EventArgs e) 
    { 
        DropDownList cbbCategoryName = (DropDownList)sender; 
        RadGrid1.MasterTableView.GetColumnSafe("CategoryNameColumn").CurrentFilterValue = cbbCategoryName.SelectedValue; 
        RadGrid1.MasterTableView.FilterExpression = "([CategoryName] LIKE \'%" + ccbbCategoryName.SelectedValue + "%\') "
        this.RadGrid1.MasterTableView.GetColumnSafe("CategoryNameColumn").CurrentFilterFunction = GridKnownFunction.EqualTo; 
        RadGrid1.MasterTableView.Rebind(); 
    }  


Hope this helps.

Thanks,
Princy
0
tom cat
Top achievements
Rank 1
answered on 22 Feb 2010, 08:03 AM

I wonder that if I do so (use FilterExpression), all other filter functions (on other columns) could be reset.

I wonder that if I do so, all other filter functions (on other columns) could be reset.
0
Iana Tsolova
Telerik team
answered on 24 Feb 2010, 03:12 PM
Hi tom,

Instead of modifying the grid FilterExpression, you can try firing the grid filter explicitly. Please find more information on how to achieve that here.

Regards,
Iana
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.
0
tom cat
Top achievements
Rank 1
answered on 24 Feb 2010, 07:50 PM
I don't understand, please explain more comprehensively. I 've clicked on your link but I don't understand anything
0
Accepted
Iana Tsolova
Telerik team
answered on 25 Feb 2010, 02:49 PM
Hello tom,

Please find attached a sample project illustrating the solution suggested in my previous post. Check it out and let me know if it works for you and if I missed something out.

Greetings,
Iana
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.
0
tom cat
Top achievements
Rank 1
answered on 27 Feb 2010, 08:27 AM
Thank you!
Tags
Grid
Asked by
tom cat
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
tom cat
Top achievements
Rank 1
Iana Tsolova
Telerik team
Share this question
or