I am having a problem with a custom filter editor when DataKeyValue and DataTextValue differe.
Most of the code I am using was taken from the custom field editors demo.
Filtering the related grid works fine but the text field is showing the wrong text after a click on the "Apply" button.
If I click on "Add Expression" I get a filled combo box where I can select the order type by name.
Clicking on "Apply" filters the grids contents as expected. But the reacently added expression shows the integer value in it's text field.
I would like to show the localized text out of the combo box.
This is the filter extracted from the page.
OrderListGrid is a RadGrid using a sql data source to a simple table.
This table has a column "Type" which stores the order types as an integer value.
This integer value should not be shown to the customer, but replaced by a localized text within the filter combo box.
Therefore I've created a DataTable and assigned it to the custom filter editor as in the demo.
Any suggestions?
Most of the code I am using was taken from the custom field editors demo.
Filtering the related grid works fine but the text field is showing the wrong text after a click on the "Apply" button.
If I click on "Add Expression" I get a filled combo box where I can select the order type by name.
Clicking on "Apply" filters the grids contents as expected. But the reacently added expression shows the integer value in it's text field.
I would like to show the localized text out of the combo box.
This is the filter extracted from the page.
<telerik:RadFilter ID="Filter" runat="server" FilterContainerID="OrderListGrid" OnFieldEditorCreating="Filter_FieldEditorCreating" CssClass="RadFilter RadFilter_Default " > <FieldEditors> <csc:RadFilterDropDownEditor FieldName="Type" DataValueField="Type" DataTextField="Name" DataType="System.Int32" /> <telerik:RadFilterTextFieldEditor FieldName="Order" DataType="System.String" /> <telerik:RadFilterDateFieldEditor FieldName="Start" DataType="System.DateTime" /> <telerik:RadFilterDateFieldEditor FieldName="End" DataType="System.DateTime" />
</FieldEditors>
</telerik:RadFilter>This table has a column "Type" which stores the order types as an integer value.
This integer value should not be shown to the customer, but replaced by a localized text within the filter combo box.
Therefore I've created a DataTable and assigned it to the custom filter editor as in the demo.
private void InitializeFilterCtrl(){ RadFilterDropDownEditor dropTypFilter = Filter.FieldEditors[0] as RadFilterDropDownEditor; if (OrderTypesTable == null) { OrderTypesTable = GetOrderTypeTable(); } dropTypFilter.DataSource = OrderTypesTable;}
private DataTable GetOrderTypeTable(){ DataTable tab = new DataTable(); tab.Columns.Add("Type"); tab.Columns.Add("Name"); tab.Rows.Add( new object [] { (int)OrderType.Final, LocalizationUtils.GetOrderName(OrderType.Final) }); tab.Rows.Add(new object[] { (int)OrderType.Intermediate, LocalizationUtils.GetOrderName(OrderType.Intermediate) }); tab.Rows.Add(new object[] { (int)OrderType.Piece, LocalizationUtils.GetOrderName(OrderType.Piece) });<br> tab.Rows.Add(new object[] { (int)OrderType.Batch, LocalizationUtils.GetOrderName(OrderType.Batch) }); return tab;}LocalizationUtils.GetOrderName(..) just returns the localized text out of the resources.public class RadFilterDropDownEditor : RadFilterDataFieldEditor{ protected override void CopySettings(RadFilterDataFieldEditor baseEditor) { base.CopySettings(baseEditor); var editor = baseEditor as RadFilterDropDownEditor; if (editor != null) { DataSource = editor.DataSource; DataTextField = editor.DataTextField; DataValueField = editor.DataValueField; } } public override System.Collections.ArrayList ExtractValues() { ArrayList list = new ArrayList(); list.Add(_combo.SelectedValue); return list; } public override void InitializeEditor(System.Web.UI.Control container) { _combo = new RadComboBox(); _combo.ID = "MyCombo"; _combo.DataTextField = DataTextField; _combo.DataValueField = DataValueField; _combo.DataSource = DataSource; _combo.DataBind(); container.Controls.Add(_combo); } public override void SetEditorValues(System.Collections.ArrayList values) { if (values != null && values.Count > 0) { if (values[0] == null) return; var item = _combo.FindItemByValue(values[0].ToString()); if (item != null) item.Selected = true; } } public string DataTextField { get { return (string)ViewState["DataTextField"] ?? string.Empty; } set { ViewState["DataTextField"] = value; } } public string DataValueField { get { return (string)ViewState["DataValueField"] ?? string.Empty; } set { ViewState["DataValueField"] = value; } } public DataTable DataSource { get { return (DataTable)ViewState["DataSource"] ?? new DataTable(); } set { ViewState["DataSource"] = value; } } private RadComboBox _combo;}Any suggestions?