Hello,
I am having an issue using a custom drop down editor in the rad filter. When I set the value of my first filter criteria and click the link to add more criteria I lose the value of the first criteria I set. I think the issue has to do with when the handler is added for setting the value is after the binding already takes place.
Thanks!
Don
MyRuntimeEditor.aspx
MyRuntimeEditor.aspx.vb
CustomEditor.vb
DataObject.vb
Thanks
I am having an issue using a custom drop down editor in the rad filter. When I set the value of my first filter criteria and click the link to add more criteria I lose the value of the first criteria I set. I think the issue has to do with when the handler is added for setting the value is after the binding already takes place.
Thanks!
Don
MyRuntimeEditor.aspx
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="MyRuntimeEditor.aspx.vb" Inherits="MyRuntimeEditor" %><%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %><%@ Register Namespace="MyCustomEditors" TagPrefix="mycustom" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head id="Head1" runat="server"> <title></title></head><body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <div> <asp:Button ID="Button1" Text="Postback" runat="server" /> <telerik:RadFilter runat="server" OnFieldEditorCreating="RadFilter1_FieldEditorCreating" OnApplyExpressions="RadFilter1_ApplyExpressions"> <FieldEditors> <mycustom:MyRadFilterDropDownEditor DataTextField="Text" DataValueField="Value" FieldName="USR_ID" DataType="System.Int32" DisplayName="User name" DDLType="Usernames" /> <mycustom:MyRadFilterDropDownEditor DataTextField="Text" DataValueField="Value" FieldName="PNT_ID" DataType="System.Int32" DisplayName="Note" DDLType="PartyNotes" /> <mycustom:MyRadFilterDropDownEditor DataTextField="Text" DataValueField="Value" FieldName="PGT_ID" DataType="System.Int32" DisplayName="Group" DDLType="PartyGroups" /> </FieldEditors> </telerik:RadFilter> Expression: <asp:Label runat="server" ID="Log"/> </div> </form></body></html>MyRuntimeEditor.aspx.vb
Imports SystemImports System.Collections.GenericImports System.LinqImports System.WebImports System.Web.UIImports System.Web.UI.WebControlsImports Telerik.Web.UIImports CustomEditorsImports MyCustomEditorsPartial Class MyRuntimeEditor Inherits System.Web.UI.Page Protected Sub RadFilter1_ApplyExpressions(ByVal sender As Object, ByVal e As RadFilterApplyExpressionsEventArgs) Dim provider As New RadFilterSqlQueryProvider() provider.ProcessGroup(e.ExpressionRoot) Log.Text = provider.Result End Sub Protected Sub RadFilter1_FieldEditorCreating(ByVal sender As Object, ByVal e As RadFilterFieldEditorCreatingEventArgs) e.Editor = New MyRadFilterDropDownEditor() End SubEnd ClassCustomEditor.vb
Imports SystemImports System.Collections.GenericImports System.LinqImports System.WebImports Telerik.Web.UIImports System.Web.UIImports System.CollectionsNamespace CustomEditors Public Class RadFilterDropDownEditor Inherits RadFilterDataFieldEditor Public Property DataTextField() As String Get Return If(DirectCast(ViewState("DataTextField"), String), String.Empty) End Get Set(ByVal value As String) ViewState("DataTextField") = value End Set End Property Public Property DataValueField() As String Get Return If(DirectCast(ViewState("DataValueField"), String), String.Empty) End Get Set(ByVal value As String) ViewState("DataValueField") = Value End Set End Property Public Property DataSourceID() As String Get Return If(DirectCast(ViewState("DataSourceID"), String), String.Empty) End Get Set(ByVal value As String) ViewState("DataSourceID") = Value End Set End Property Private _combo As RadComboBox Protected Overrides Sub CopySettings(ByVal baseEditor As RadFilterDataFieldEditor) MyBase.CopySettings(baseEditor) Dim editor As RadFilterDropDownEditor = TryCast(baseEditor, RadFilterDropDownEditor) If editor IsNot Nothing Then DataSourceID = editor.DataSourceID DataTextField = editor.DataTextField DataValueField = editor.DataValueField End If End Sub Public Overrides Function ExtractValues() As System.Collections.ArrayList Dim list As New ArrayList() list.Add(_combo.SelectedValue) Return list End Function Public Overrides Sub InitializeEditor(container As System.Web.UI.Control) _combo = New RadComboBox() _combo.ID = "MyCombo" _combo.DataTextField = DataTextField _combo.DataValueField = DataValueField _combo.DataSourceID = DataSourceID container.Controls.Add(_combo) End Sub Public Overrides Sub SetEditorValues(values As System.Collections.ArrayList) If values IsNot Nothing AndAlso values.Count > 0 Then If values(0) Is Nothing Then Return End If AddHandler _combo.DataBound, _ Sub(sender, args) Dim item As RadComboBoxItem = _combo.FindItemByValue(values(0).ToString()) If item IsNot Nothing Then item.Selected = True End If End Sub End If End Sub End ClassEnd NamespaceDataObject.vb
Imports Microsoft.VisualBasicImports System.DataPublic Class DataObject Public Function GetUsers() As DataTable Dim dt As DataTable = CreateDataTable() dt.Rows.Add(CreateDataRow(dt.NewRow(), 1, "Joe One")) dt.Rows.Add(CreateDataRow(dt.NewRow(), 2, "Joe Two")) dt.Rows.Add(CreateDataRow(dt.NewRow(), 3, "Joe Three")) dt.Rows.Add(CreateDataRow(dt.NewRow(), 4, "Joe Four")) Return dt End Function Public Function GetNoteTypes() As DataTable Dim dt As DataTable = CreateDataTable() dt.Rows.Add(CreateDataRow(dt.NewRow(), 1, "Internal")) dt.Rows.Add(CreateDataRow(dt.NewRow(), 2, "Email")) dt.Rows.Add(CreateDataRow(dt.NewRow(), 3, "Phone")) dt.Rows.Add(CreateDataRow(dt.NewRow(), 4, "Sales Call")) Return dt End Function Public Function GetPartyGroups() As DataTable Dim dt As DataTable = CreateDataTable() dt.Rows.Add(CreateDataRow(dt.NewRow(), 1, "Internet Lead")) dt.Rows.Add(CreateDataRow(dt.NewRow(), 2, "Website")) dt.Rows.Add(CreateDataRow(dt.NewRow(), 3, "Cold calling")) dt.Rows.Add(CreateDataRow(dt.NewRow(), 4, "Phoned in")) Return dt End Function Private Function CreateDataRow(ByVal r As DataRow, ByVal Value As Integer, ByVal Text As String) As DataRow r("Value") = Value r("Text") = Text Return r End Function Private Function CreateDataTable() As DataTable Dim dt As New DataTable dt.Columns.Add("Value", GetType(Integer)) dt.Columns.Add("Text", GetType(String)) Return dt End FunctionEnd ClassThanks