I have been using 3 custom filters in a grid. I wanted to save the value of the filter to filter on multiple values. Do I have to change something in the code
public class MyCustomFilteringColumn : GridBoundColumn
{
//RadGrid will call this method when it initializes the controls inside the filtering item cells
protected override void SetupFilterControls(TableCell cell)
{
base.SetupFilterControls(cell);
cell.Controls.RemoveAt(0);
Telerik.Web.UI.RadComboBox combo = new Telerik.Web.UI.RadComboBox();
combo.ID = ("RadComboBox1" + this.UniqueName);
combo.ShowToggleImage = false;
combo.Skin = "Office2007";// "Web20";
combo.EnableLoadOnDemand = true;
combo.AutoPostBack = true;
combo.MarkFirstMatch = true;
combo.Height = Unit.Pixel(100);
combo.Width = Unit.Pixel(60);
combo.ItemsRequested += this.list_ItemsRequested;
combo.SelectedIndexChanged += this.list_SelectedIndexChanged;
cell.Controls.AddAt(0, combo);
cell.Controls.RemoveAt(1);
}
//RadGrid will cal this method when the value should be set to the filtering input control(s)
protected override void SetCurrentFilterValueToControl(TableCell cell)
{
base.SetCurrentFilterValueToControl(cell);
RadComboBox combo = (RadComboBox)cell.Controls[0];
if ((this.CurrentFilterValue != string.Empty))
{
combo.Text = this.CurrentFilterValue;
}
}
//RadGrid will cal this method when the filtering value should be extracted from the filtering input control(s)
protected override string GetCurrentFilterValueFromControl(TableCell cell)
{
RadComboBox combo = (RadComboBox)cell.Controls[0];
return combo.SelectedValue;
}
private void list_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)
{
((RadComboBox)o).DataTextField = this.DataField;
((RadComboBox)o).DataValueField = this.DataField;
((RadComboBox)o).DataSource = GetDataTable("SELECT DISTINCT " + this.UniqueName + " FROM Content_UserCalls WHERE " + this.UniqueName + " LIKE '" + e.Text + "%'");
((RadComboBox)o).DataBind();
((RadComboBox)o).Items.Insert(0, new RadComboBoxItem("None", ""));
}
private void list_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
{
GridFilteringItem filterItem = (GridFilteringItem)((RadComboBox)o).NamingContainer;
if ((this.UniqueName == "Index"))
{
//this is filtering for integer column type
filterItem.FireCommandEvent("Filter", new Pair("EqualTo", this.UniqueName));
}
//filtering for string column type
filterItem.FireCommandEvent("Filter", new Pair("Contains", this.UniqueName));
}
public static DataTable GetDataTable(string query)
{
DataTable myDataTable = UserCallsDAO.GetFilterColumns(query);
return myDataTable;
}
}
public class MyCustomFilteringColumn : GridBoundColumn
{
//RadGrid will call this method when it initializes the controls inside the filtering item cells
protected override void SetupFilterControls(TableCell cell)
{
base.SetupFilterControls(cell);
cell.Controls.RemoveAt(0);
Telerik.Web.UI.RadComboBox combo = new Telerik.Web.UI.RadComboBox();
combo.ID = ("RadComboBox1" + this.UniqueName);
combo.ShowToggleImage = false;
combo.Skin = "Office2007";// "Web20";
combo.EnableLoadOnDemand = true;
combo.AutoPostBack = true;
combo.MarkFirstMatch = true;
combo.Height = Unit.Pixel(100);
combo.Width = Unit.Pixel(60);
combo.ItemsRequested += this.list_ItemsRequested;
combo.SelectedIndexChanged += this.list_SelectedIndexChanged;
cell.Controls.AddAt(0, combo);
cell.Controls.RemoveAt(1);
}
//RadGrid will cal this method when the value should be set to the filtering input control(s)
protected override void SetCurrentFilterValueToControl(TableCell cell)
{
base.SetCurrentFilterValueToControl(cell);
RadComboBox combo = (RadComboBox)cell.Controls[0];
if ((this.CurrentFilterValue != string.Empty))
{
combo.Text = this.CurrentFilterValue;
}
}
//RadGrid will cal this method when the filtering value should be extracted from the filtering input control(s)
protected override string GetCurrentFilterValueFromControl(TableCell cell)
{
RadComboBox combo = (RadComboBox)cell.Controls[0];
return combo.SelectedValue;
}
private void list_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)
{
((RadComboBox)o).DataTextField = this.DataField;
((RadComboBox)o).DataValueField = this.DataField;
((RadComboBox)o).DataSource = GetDataTable("SELECT DISTINCT " + this.UniqueName + " FROM Content_UserCalls WHERE " + this.UniqueName + " LIKE '" + e.Text + "%'");
((RadComboBox)o).DataBind();
((RadComboBox)o).Items.Insert(0, new RadComboBoxItem("None", ""));
}
private void list_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
{
GridFilteringItem filterItem = (GridFilteringItem)((RadComboBox)o).NamingContainer;
if ((this.UniqueName == "Index"))
{
//this is filtering for integer column type
filterItem.FireCommandEvent("Filter", new Pair("EqualTo", this.UniqueName));
}
//filtering for string column type
filterItem.FireCommandEvent("Filter", new Pair("Contains", this.UniqueName));
}
public static DataTable GetDataTable(string query)
{
DataTable myDataTable = UserCallsDAO.GetFilterColumns(query);
return myDataTable;
}
}