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

filtering with dropdown for Boolean datatype field

3 Answers 338 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ck
Top achievements
Rank 1
ck asked on 17 Dec 2013, 09:26 AM
I got a grid with with a template column whose DataType property is set to System.Boolean and DataField property set to a bool field in the datasource. 

<telerik:GridTemplateColumn HeaderText="Physical Count Date" HeaderStyle-HorizontalAlign="Center" DataType="System.Boolean" UniqueName="CountDate" DataField="HasCount" ItemStyle-Width="100" ItemStyle-HorizontalAlign="Left" AllowFiltering="true">
                        <ItemStyle CssClass="no-border" />
                        <ItemTemplate>
                            <asp:Label ID="LabelDate" runat="server" Text='<%# ((bool)Eval("HasCount"))  ? Eval("CountDate","{0:dd/MM/yyyy}") : "Not performed" %>'></asp:Label>
                        </ItemTemplate>

I want to have a dropdown to filter it, i am following the tutorials at http://tv.telerik.com/watch/aspnet/radgrid/radgrid-for-aspnet-filtering-with-dropdown-for-checkbox-column and http://www.telerik.com/help/aspnet-ajax/grid-filtering-for-gridchecboxcolumn.html

so in my code behind i have
protected void RadGrid2_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
        {
            if (e.Item is GridFilteringItem)
            {
                GridFilteringItem filteringItem = (e.Item as GridFilteringItem);
                filteringItem["CountDate"].Controls.Clear();
                DropDownList ddList = new DropDownList();
                ddList.AutoPostBack = true;
                ddList.SelectedIndexChanged += new System.EventHandler(ddList_SelectedIndexChanged);
                ddList.Items.Add(new ListItem("Clear filter", "Empty"));
                ddList.Items.Add(new ListItem("Show all counted", "True"));
                ddList.Items.Add(new ListItem("Show all not counted", "False"));
                if (Session["ddlSelValue"] != null)
                {
                    ddList.Items.FindByValue((string)Session["ddlSelValue"]).Selected = true;
                }
                filteringItem["CountDate"].Controls.Add(ddList);
            }
        }
        protected void ddList_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            DropDownList ddList = (DropDownList)sender;
            Session["ddlSelValue"] = ddList.SelectedValue;
            switch (ddList.SelectedValue)
            {
                case "True":
                    RadGrid2.MasterTableView.FilterExpression = "([HasCount] = True) ";
                    break;
                case "False":
                    RadGrid2.MasterTableView.FilterExpression = "([HasCount] = False) ";
                    break;
                case "Empty":
                    RadGrid2.MasterTableView.FilterExpression = String.Empty;
                    break;
            }
            foreach (GridColumn column in RadGrid2.MasterTableView.Columns)
            {
                column.CurrentFilterFunction = GridKnownFunction.NoFilter;
                column.CurrentFilterValue = String.Empty;
            }
            RadGrid2.MasterTableView.Rebind();
        }

It just does not work, it renders and even submits when an option is chosen from the dropdown but it does not filter. and i am unable to figure out why.

anyone?
thanks

3 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 17 Dec 2013, 09:45 AM
Hi,

Please set EnableLinqExpressions="false" for your RadGrid and see if it helps.

ASPX:
<telerik:RadGrid ID="RadGrid2" runat="server" AutoGenerateColumns="false" EnableLinqExpressions="false" AllowFilteringByColumn="true" >

Thanks,
Princy
0
ck
Top achievements
Rank 1
answered on 17 Dec 2013, 10:24 AM
that solved it thanks. what are the implications of setting this to false though?
0
Princy
Top achievements
Rank 2
answered on 18 Dec 2013, 03:53 AM
Hi,

Setting EnableLinqExpressions to false is required for filtering grid which is bound to a DataTable. The default value of this property is true, so you would not have to set it if you use LinqDataSource,SqlDataSource etc.  It is fine to bind to a DataTable and not set EnableLinqExpressions="false" as long as you do not perform manual filtering that requires T-SQL syntax.

Thanks,
Princy

Tags
Grid
Asked by
ck
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
ck
Top achievements
Rank 1
Share this question
or