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

Problems getting custom filtering to work

3 Answers 50 Views
Grid
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 13 Sep 2011, 12:08 PM
I'm having a few problems getting the custom filtering to work. At the moment, I'm getting an error because the SQL Select command string ends up looking like this:

SELECT * FROM WTO_LinkGroups WHERE (Convert.ToString(it["group_name"]) = "3")

The inline code was borrowed from the demo and modified for my needs. Apart from the problem above, it's picking up the ID field in the example above rather than the 'group_name' field. The inline code is this:

<telerik:GridBoundColumn DataField="group_name" HeaderText="Group Name" SortExpression="group_name"
                        UniqueName="group_name">
                        <FilterTemplate>
                            <telerik:RadComboBox runat="server" ID="GroupNameComboBox" DataSourceID="SqlDataSource1"
                                DataTextField="group_name" DataValueField="group_id" Height="200px" AppendDataBoundItems="true"
                                SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("group_name").CurrentFilterValue %>'
                                OnClientSelectedIndexChanged="GroupNameIndexChanged">
                                <Items>
                                    <telerik:RadComboBoxItem Text="All" />
                                </Items>
                            </telerik:RadComboBox>
                            <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
                                <script type="text/javascript">
                                    function GroupNameIndexChanged(sender, args) {
                                        var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
                                        tableView.filter("group_name", args.get_item().get_value(), "EqualTo");
 
                                    }
                                </script>
                            </telerik:RadScriptBlock>
                        </FilterTemplate>
                    </telerik:GridBoundColumn>

Oh ... and here's the codebehind:

protected void RefreshCombos()
    {
        SqlDataSource1.SelectCommand = "SELECT * FROM WTO_LinkGroups WHERE " + RadGrid1.MasterTableView.FilterExpression.ToString();
        SqlDataSource1.SelectCommandType = System.Web.UI.WebControls.SqlDataSourceCommandType.Text;
        RadGrid1.MasterTableView.Rebind();
    }

The error crops up on the Rebind.

Where is the problem being caused?

Thanks.

3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 16 Sep 2011, 09:35 AM
Hello David,

RadGrid can generate T-SQL-style filter expressions for you provided that you set EnableLinqExpressions property to false.
<telerik:RadGrid ID="RadGrid1" runat="server" EnableLinqExpressions="false">

I hope this helps

Best regards,
Daniel
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal
0
David
Top achievements
Rank 1
answered on 16 Sep 2011, 10:40 AM
Thanks. I'll give it a try, although I've removed the custom filtering for the time being because of other problems when using it in the Hierarchical grid. I have an option button on the grid that allows the user to set various things to help with their workflow. The options pop up in a RadWindow.and the window, when closed, will refresh the grid. When the grid refreshes, code in the codebehind will load up the options from the database and set up the grid accordingly.

One of the options is to switch the grid between its default filtering and custom filtering. The problem I have, however, is that when custom filtering is switched off, it seems to produce an error which then stops all the buttons on the grid from working. It seemed to be working okay when the grid was operating as a standard grid, but then it stopped working when I added a level of hierarchy. The code I'm using to switch off the custom filtering is simply:

if (!linkGroupFiltered)
 {
     RadGrid1.MasterTableView.Columns[2].FilterTemplate = null;
     RadGrid1.MasterTableView.Columns[3].FilterTemplate = null;
 }
 This is is in the Page_Load method.
0
Daniel
Telerik team
answered on 21 Sep 2011, 09:59 PM
Hello David,

Please try to invoke RadGrid.Rebind after clearing the filter expression. Make sure however, that this metod is called only when needed and not on every postback.

Regards,
Daniel
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
Grid
Asked by
David
Top achievements
Rank 1
Answers by
Daniel
Telerik team
David
Top achievements
Rank 1
Share this question
or