using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
namespace MFP_ASP
{
public class CustomFilteringColumn : GridBoundColumn
{
private object listDataSource = null;
//RadGrid calls 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);
DropDownList list = new DropDownList();
list.ID = "list" + this.DataField;
list.AutoPostBack = true;
list.SelectedIndexChanged += new EventHandler(list_SelectedIndexChanged);
cell.Controls.AddAt(0, list);
cell.Controls.RemoveAt(1);
list.DataTextField = this.DataField;
list.DataValueField = this.DataField;
list.DataSource = this.ListDataSource;
}
void list_SelectedIndexChanged(object sender, EventArgs e)
{
GridFilteringItem filterItem = (sender as DropDownList).NamingContainer as GridFilteringItem;
if (this.DataType == System.Type.GetType("System.Int32") || this.DataType == System.Type.GetType("System.Int16") || this.DataType == System.Type.GetType("System.Int64"))
{
filterItem.FireCommandEvent("Filter", new Pair("EqualTo", this.UniqueName));
}
else
// treat everything else like a string
filterItem.FireCommandEvent("Filter", new Pair("Contains", this.UniqueName));
}
public object ListDataSource
{
get
{
return this.listDataSource;
}
set
{
listDataSource = value;
}
}
//RadGrid calls this method when the value should be set to the filtering input control(s)
protected override void SetCurrentFilterValueToControl(TableCell cell)
{
base.SetCurrentFilterValueToControl(cell);
DropDownList list = (DropDownList)cell.Controls[0];
if (this.CurrentFilterValue != string.Empty)
{
list.SelectedValue = this.CurrentFilterValue;
}
}
//RadGrid calls this method to extract the filtering value from the filtering input control(s)
protected override string GetCurrentFilterValueFromControl(TableCell cell)
{
DropDownList list = (DropDownList)cell.Controls[0];
return list.SelectedValue;
}
protected override string GetFilterDataField()
{
return this.DataField;
}
}
}
<%@ register namespace="MFP_ASP" tagprefix="custom" %>
<MasterTableView AutoGenerateColumns="False" DataSourceID="PMPerformanceDataSource" DataKeyNames="Branch,Cust_No" PageSize="25">
<Columns>
<custom:CustomFilteringColumn DataField="Branch" HeaderText="Branch" SortExpression="Branch" UniqueName="Branch" ListDataSource="SQLDataSourcefrmPM_Branch">
<ColumnValidationSettings>
<ModelErrorMessage Text="" />
</ColumnValidationSettings>
</custom:CustomFilteringColumn>I have copied the code from the demo. I added the reference in the heading. But the control is not recognized. I named mine CustomFilteringColumn and have it in a class file in the root folder. I only want to use dropdownlistboxes for the filters so if I cannot get it to work there is no sale of this product to me.
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
namespace MFP_ASP
{
public class CustomFilteringColumn : GridBoundColumn
{
private object listDataSource = null;
//RadGrid calls 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);
DropDownList list = new DropDownList();
list.ID = "list" + this.DataField;
list.AutoPostBack = true;
list.SelectedIndexChanged += new EventHandler(list_SelectedIndexChanged);
cell.Controls.AddAt(0, list);
cell.Controls.RemoveAt(1);
list.DataTextField = this.DataField;
list.DataValueField = this.DataField;
list.DataSource = this.ListDataSource;
}
void list_SelectedIndexChanged(object sender, EventArgs e)
{
GridFilteringItem filterItem = (sender as DropDownList).NamingContainer as GridFilteringItem;
if (this.DataType == System.Type.GetType("System.Int32") || this.DataType == System.Type.GetType("System.Int16") || this.DataType == System.Type.GetType("System.Int64"))
{
filterItem.FireCommandEvent("Filter", new Pair("EqualTo", this.UniqueName));
}
else
// treat everything else like a string
filterItem.FireCommandEvent("Filter", new Pair("Contains", this.UniqueName));
}
public object ListDataSource
{
get
{
return this.listDataSource;
}
set
{
listDataSource = value;
}
}
//RadGrid calls this method when the value should be set to the filtering input control(s)
protected override void SetCurrentFilterValueToControl(TableCell cell)
{
base.SetCurrentFilterValueToControl(cell);
DropDownList list = (DropDownList)cell.Controls[0];
if (this.CurrentFilterValue != string.Empty)
{
list.SelectedValue = this.CurrentFilterValue;
}
}
//RadGrid calls this method to extract the filtering value from the filtering input control(s)
protected override string GetCurrentFilterValueFromControl(TableCell cell)
{
DropDownList list = (DropDownList)cell.Controls[0];
return list.SelectedValue;
}
protected override string GetFilterDataField()
{
return this.DataField;
}
}
}
<%@ register namespace="MFP_ASP" tagprefix="custom" %>
<MasterTableView AutoGenerateColumns="False" DataSourceID="PMPerformanceDataSource" DataKeyNames="Branch,Cust_No" PageSize="25">
<Columns>
<custom:CustomFilteringColumn DataField="Branch" HeaderText="Branch" SortExpression="Branch" UniqueName="Branch" ListDataSource="SQLDataSourcefrmPM_Branch">
<ColumnValidationSettings>
<ModelErrorMessage Text="" />
</ColumnValidationSettings>
</custom:CustomFilteringColumn>I have copied the code from the demo. I added the reference in the heading. But the control is not recognized. I named mine CustomFilteringColumn and have it in a class file in the root folder. I only want to use dropdownlistboxes for the filters so if I cannot get it to work there is no sale of this product to me.