This is a migrated thread and some comments may be shown as answers.

Using Dropdownlistbox for Filter

1 Answer 59 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rodd
Top achievements
Rank 1
Rodd asked on 02 Jun 2014, 11:43 PM
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.

1 Answer, 1 is accepted

Sort by
0
Kostadin
Telerik team
answered on 05 Jun 2014, 01:50 PM
Hello Rodd,

Note that all classes should be placed in the App_Code directory of your project and not in the root folder in order to work correctly. For your convenience I prepared a small sample based on your code and attached it to this thread. Please give it a try and let me know about the result.

Regards,
Kostadin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Rodd
Top achievements
Rank 1
Answers by
Kostadin
Telerik team
Share this question
or