databinding a CustomDropDownEditor for a RadFilter

6 posts, 0 answers
  1. Don Tompkins
    Don Tompkins avatar
    17 posts
    Member since:
    Apr 2008

    Posted 30 Mar 2011 Link to this post

    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
    <%@ 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">
    <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 System
    Imports System.Collections.Generic
    Imports System.Linq
    Imports System.Web
    Imports System.Web.UI
    Imports System.Web.UI.WebControls
    Imports Telerik.Web.UI
    Imports CustomEditors
    Imports MyCustomEditors
     
    Partial 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 Sub
     
    End Class

    CustomEditor.vb
    Imports System
    Imports System.Collections.Generic
    Imports System.Linq
    Imports System.Web
    Imports Telerik.Web.UI
    Imports System.Web.UI
    Imports System.Collections
     
    Namespace 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 Class
    End Namespace

    DataObject.vb
    Imports Microsoft.VisualBasic
    Imports System.Data
     
    Public 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 Function
    End Class


    Thanks
  2. Don Tompkins
    Don Tompkins avatar
    17 posts
    Member since:
    Apr 2008

    Posted 31 Mar 2011 Link to this post

    I figured out this issue. Thanks!

    Don.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Warn
    Warn avatar
    6 posts
    Member since:
    Apr 2011

    Posted 21 Apr 2011 Link to this post

    Hi Don,

    I am also facing the same issue..My case the in the custom editor, radTreeview is being used as the item for radCombobox.
    Any suggestion or how did you solve your issue.

    Thanks
    Warn
  5. Don Tompkins
    Don Tompkins avatar
    17 posts
    Member since:
    Apr 2008

    Posted 25 Apr 2011 Link to this post

    Hi Warn,

    I removed the AddHandler code and called the code directly. It was an issue where the databound event was called before the AddHandler was created.

    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
    Take the code sample above and change it to the code sample below.
    Public Overrides Sub SetEditorValues(ByVal values As System.Collections.ArrayList)
        If values IsNot Nothing AndAlso values.Count > 0 Then
            If values(0) Is Nothing Then
                Return
            End If
            Dim item = ddlList.FindItemByValue(values(0).ToString())
            If item IsNot Nothing Then
                item.Selected = True
            End If
        End If
    End Sub

    Regards,

    Don
  6. Warn
    Warn avatar
    6 posts
    Member since:
    Apr 2011

    Posted 26 Apr 2011 Link to this post

    HI Don,

    Thanks for your reply.
    What is "ddlList"? is it your combobox?
    Dim item = ddlList.FindItemByValue(values(0).ToString())

    Thanks
    Warn
  7. Don Tompkins
    Don Tompkins avatar
    17 posts
    Member since:
    Apr 2008

    Posted 27 Apr 2011 Link to this post

    Yes. The first code snippet was from the original post, and the second code snippet was from my code after I renamed the combo box.

    Regards,

    Don
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017