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

Odd Behavior when RadComboBox w/ checkboxes used as Filter

1 Answer 25 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jay
Top achievements
Rank 1
Jay asked on 17 Aug 2012, 05:07 PM
I've setup a custom filter using a RadComboBox with checkboxes by inheriting from GridBoundColumn.   I have two columns out of about ten that use this custom filter column.  The RadComboBox has AutoPostBack set to true.  Strangely, the combo box triggers the SelectedIndexChanged event on initial page load, so as soon as the page loads the grid immediately reloads (it's wrapped in a RadAjaxPanel).  I've noticed though that this doesn't happen when I turn off ajax on the surrounding ajax panel.  
The bigger problem I have, which isn't fixed by turning off ajax, is that if I make a selection in the second RadComboBox, it triggers the SelectedIndexChanged event in the first one, instead of the correct one.  Just to make sure that this problem is specific to the RadComboBox, I did a test using a regular DropDownList and it worked fine.  My code is below.  Please let me know if there are any changes I can make to get this working.  The version of the RadControls I'm using is about a year old so I guess it's possible this is a bug that's been fixed in a newer version [UPDATE: I've done a test with the latest version of RadControls and the problem persists].

public class GridBoundMultiSelectFilterColumn : GridBoundColumn
{
    private readonly XrefGateway _xrefGateway = new XrefGateway();
 
    protected override void SetupFilterControls(TableCell cell)
    {
        base.SetupFilterControls(cell);
        cell.Controls.RemoveAt(0);
 
        var comboBox = new RadComboBox() { ID = this.DataField + "Filter", AutoPostBack = true, CheckBoxes = true, EnableCheckAllItemsCheckBox = true};
        IList<string> options = _xrefGateway.GetUniqueColumnValues(DataField);
        foreach (var option in options)
        {
            comboBox.Items.Add(new RadComboBoxItem(option));
        }
        cell.Controls.AddAt(0, comboBox);
        cell.Controls.RemoveAt(1);
        comboBox.SelectedIndexChanged += comboBox_SelectedIndexChanged;
 
        
        if(Filter != null)
        {
            foreach (RadComboBoxItem item in comboBox.Items)
            {
                item.Checked = Filter.Values.Contains(item.Text);
            }
        }
    }
 
 
 
    void comboBox_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
    {
        var comboBox = (RadComboBox)sender;
        if ((Filter == null || Filter.Values.Count == 0) && comboBox.CheckedItems.Count == 0)
            return;
        Filter = new MultiSelectFilter() { ColumnName = DataField };
        foreach (RadComboBoxItem item in comboBox.CheckedItems)
        {
            Filter.Values.Add(item.Text);
        }
 
        var filterItem = comboBox.NamingContainer as GridFilteringItem;
 
 
        filterItem.FireCommandEvent("CustomFilter", Filter);
    }
 
 
    protected override string GetFilterDataField()
    {
        return this.DataField;
    }
 
    private MultiSelectFilter Filter
    {
        get { return (MultiSelectFilter) ViewState["Filter"]; }
        set { ViewState["Filter"] = value; }
    }
}
   

1 Answer, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 22 Aug 2012, 03:54 PM
Hi Jay,

May I ask you to open a formal support ticket and send us a sample project where the described problem can be observed. Thus we will be able to debug it locally and advice you further. You can follow the instructions from this blog post to isolate the problem in a sample project.

Greetings,
Pavlina
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
Jay
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Share this question
or