I have a grid with filter templates looking like this:
<FilterTemplate>
<telerik:RadComboBox ID="ddCategory3" runat="server" DropDownAutoWidth="Enabled"
AppendDataBoundItems="true" CausesValidation="false"
DataTextField="Category" DataValueField="Category"
DataSourceID="dsCategory" SelectedValue='<%# TryCast(Container, GridItem).OwnerTableView.GetColumn("Category").CurrentFilterValue %>' OnClientSelectedIndexChanged="Category">
<Items>
<telerik:RadComboBoxItem Text="All" />
</Items>
</telerik:RadComboBox>
<telerik:RadScriptBlock ID="RadScriptBlockCategory" runat="server">
<script type="text/javascript">
function Category(sender, args) {
var tableView = $find("<%# TryCast(Container, GridItem).OwnerTableView.ClientID %>");
tableView.filter("Category", args.get_item().get_value(), "EqualTo");
}
</script>
</telerik:RadScriptBlock>
</FilterTemplate>
If I have just one item with value "ABC" in column "Category" and I filter my grid by that column and value, I will receive just one item. My grid has delete functionality. If I try to delete this item, I am getting error "Selection is out of range." after the item is deleted. I figured out, that it is because my combobox data source contains distinct values for this column. When I delete last Item with value "ABC" combobox rebinds and doesn't have item ABC anymore, but current filter value is still ABC, so it fails.
I try to solve it by removing SelectedValue='<%# TryCast(Container, GridItem).OwnerTableView.GetColumn("Category").CurrentFilterValue %>' and adding ondatabound function, where I check if current value exists in item collection. I exists, I set set selected value as current filter value. Otherwise I set selection to ALL and clear the filter . It is all works fine if I only have filter for that one column. But I have multiple columns and ideally I would prefer not to clear FilterExpression completely, but just remove a portion that represents this column filter. It there any easy solution for that other then parsing the Filter expression manually? Or may be my approach to solving the issue is not the best one? I am open to suggestions.