I am having problems when adding two columns to a grid which rely on filtering though a combobox. The majority of the examples and support for custom filtering on a RadGrid is through the markup (.aspx). This does not apply for me because I am generating the RadGrid completely dynamically in the code-behind.
I have successfully created a custom filtering on a column. Please find below the snippet which loads the AssignedTo column. The AssignedTo column has a combobox filter implemented through AssignedToCustomBoundFilteringColumn.
See below for the implementation of the AssignedToCustomBoundFilteringColumn
This is working fine. But I have since created a new column, which is basically an identical implementation
N.B. I have implemented the ColumnCreating event handler
I am at a loss why introducing the State filtering stuffs up the AssignedTo filtering.
I have successfully created a custom filtering on a column. Please find below the snippet which loads the AssignedTo column. The AssignedTo column has a combobox filter implemented through AssignedToCustomBoundFilteringColumn.
var assignedToCol = new AssignedToCustomBoundFilteringColumn();assignedToCol.DataField = "AssessmentManagerUser.FullName";assignedToCol.HeaderText = "Assigned To"; assignedToCol.UniqueName = "AssignedTo";assignedToCol.SortExpression = "AssessmentManagerUser.FullName";PlaApplicationsGrid.MasterTableView.Columns.Add(assignedToCol);See below for the implementation of the AssignedToCustomBoundFilteringColumn
private class AssignedToCustomBoundFilteringColumn : GridBoundColumn{ protected override void SetupFilterControls(TableCell cell) { RadComboBox rcBox = new RadComboBox(); rcBox.ID = "AssignedToFilterDropDownList"; rcBox.AutoPostBack = true; rcBox.DataTextField = "FullName"; rcBox.DataValueField = "FullName"; rcBox.SelectedIndexChanged += rcBox_SelectedIndexChanged; rcBox.ItemDataBound += new RadComboBoxItemEventHandler(rcBox_ItemDataBound); var plaOfficers = ApplicationUserManager.Instance.GetBySecurityRoles(new string[] { KnownRoleNames.PLAOfficer }) as List<ApplicationUser>; var unassignedUser = ApplicationUserManager.Instance.GetUnassigned(); ApplicationUser tempEmptyUser = new ApplicationUser(); tempEmptyUser.Person = new Person(); tempEmptyUser.Person.FirstName = "empty"; tempEmptyUser.Person.Surname = ""; plaOfficers.Insert(0, unassignedUser); plaOfficers.Insert(0, tempEmptyUser); rcBox.DataSource = plaOfficers; rcBox.DataBind(); //rcBox.Items[0].Text = "Unassigned"; cell.Controls.Add(rcBox); } private void rcBox_ItemDataBound(object sender, RadComboBoxItemEventArgs e) { // Need this unless you want the item text to say "Unassignred Unassigned" if (e.Item.Text == ApplicationUserManager.Instance.GetUnassigned().FullName) { e.Item.Text = ApplicationUserManager.Instance.GetUnassigned().Username; } else if (e.Item.Text == "empty ") { e.Item.Text = " "; } } protected override void SetCurrentFilterValueToControl(TableCell cell) { if (!(this.CurrentFilterValue == "")) { ((RadComboBox)cell.Controls[0]).Items.FindItemByValue(this.CurrentFilterValue).Selected = true; } } protected override string GetCurrentFilterValueFromControl(TableCell cell) { string currentValue = ((RadComboBox)cell.Controls[0]).SelectedItem.Value; this.CurrentFilterFunction = (currentValue != "" && currentValue != "empty ") ? GridKnownFunction.EqualTo : GridKnownFunction.NoFilter; return currentValue; } private void rcBox_SelectedIndexChanged(object sender, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e) { ((GridFilteringItem)(((RadComboBox)sender).Parent.Parent)).FireCommandEvent("Filter", new Pair()); }}This is working fine. But I have since created a new column, which is basically an identical implementation
var stateCol = new StateCustomBoundFilteringColumn(); // AssignedTo column filtering breaks when this column is introduced//var stateCol = new GridBoundColumn();stateCol.DataField = "State.Description";stateCol.HeaderText = "State";stateCol.UniqueName = "State";stateCol.SortExpression = "State.Description";PlaApplicationsGrid.MasterTableView.Columns.Add(stateCol);private class StateCustomBoundFilteringColumn : GridBoundColumn{ protected override void SetupFilterControls(TableCell cell) { RadComboBox rcBox = new RadComboBox(); rcBox.ID = "StateFilterDropDownList"; rcBox.AutoPostBack = true; rcBox.DataTextField = "Description"; rcBox.DataValueField = "Name"; rcBox.SelectedIndexChanged += rcBox_SelectedIndexChanged; var validStates = ApplicationStateManager.Instance.GetAllMasterBuildStates(); ApplicationState tempEmptyState = new ApplicationState(); tempEmptyState.Name = "empty"; tempEmptyState.Description = ""; validStates.Insert(0, tempEmptyState); rcBox.DataSource = validStates; rcBox.DataBind(); //rcBox.Items[0].Text = "Unassigned"; cell.Controls.Add(rcBox); } protected override void SetCurrentFilterValueToControl(TableCell cell) { if (!(this.CurrentFilterValue == "")) { ((RadComboBox)cell.Controls[0]).Items.FindItemByValue(this.CurrentFilterValue).Selected = true; } } protected override string GetCurrentFilterValueFromControl(TableCell cell) { string currentValue = ((RadComboBox)cell.Controls[0]).SelectedItem.Value; this.CurrentFilterFunction = (currentValue != "" && currentValue != "empty ") ? GridKnownFunction.EqualTo : GridKnownFunction.NoFilter; return currentValue; } private void rcBox_SelectedIndexChanged(object sender, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e) { ((GridFilteringItem)(((RadComboBox)sender).Parent.Parent)).FireCommandEvent("Filter", new Pair()); }}N.B. I have implemented the ColumnCreating event handler
I am at a loss why introducing the State filtering stuffs up the AssignedTo filtering.