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].
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; }
}
}