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

Filter Not Working:

1 Answer 71 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Modo
Top achievements
Rank 1
Modo asked on 14 Feb 2011, 07:38 AM
Hi,

I'm having some problems with creating a custom filter control for something that I would assume is easy to do. I have created another in the project that is bound to a enum that works fine, but this filter which is bound to a class is failing:

The error



The markup

<uc:OrderStatusFilterColumn AllowFiltering="true" AutoPostBackOnFilter="true" DataField="Status" HeaderText="Status" ShowFilterIcon="false"
    UniqueName="Status" >
    <ItemTemplate>
        <%# DirectCast(Container.DataItem, Quote).Status.Name%>
    </ItemTemplate>
</uc:OrderStatusFilterColumn>

the custom control

Public Class OrderStatusFilterColumn
    Inherits GridTemplateColumn
 
    Protected Overrides Sub SetupFilterControls(ByVal cell As TableCell)
 
        Dim combo = New RadComboBox()
        combo.ID = "statusCombo"
        combo.AutoPostBack = True
 
        'defaults
        combo.Items.Add(New RadComboBoxItem With {.Text = "All", .Value = "-1"})
 
        For Each currentStatus As Status In Status.GetAllStatus()
 
            combo.Items.Add(New RadComboBoxItem With {.Text = currentStatus.Name, .Value = CStr(currentStatus.StatusID)})
        Next
 
        AddHandler combo.SelectedIndexChanged, AddressOf comboSelectionChanged
 
        '--------------
 
        cell.Controls.Add(combo)
 
    End Sub
 
    Private Sub comboSelectionChanged(ByVal sender As Object, ByVal e As RadComboBoxSelectedIndexChangedEventArgs)
 
        Dim combo = CType(sender, RadComboBox)
        Dim filterItem = TryCast(combo.NamingContainer, GridFilteringItem)
 
        filterItem.FireCommandEvent("Filter", New Pair())
 
    End Sub
 
    Protected Overrides Sub SetCurrentFilterValueToControl(ByVal cell As TableCell)
 
        If Not String.IsNullOrEmpty(CurrentFilterValue) Then
            CType(cell.Controls(0), RadComboBox).Items.FindItemByValue(CurrentFilterValue).Selected = True
        End If
 
    End Sub
 
    Protected Overrides Function GetCurrentFilterValueFromControl(ByVal cell As TableCell) As String
 
        Dim currentValue = CType(cell.Controls(0), RadComboBox).SelectedItem.Value
 
        If String.IsNullOrEmpty(currentValue) Then
            CurrentFilterFunction = GridKnownFunction.NoFilter
            Return "-1"
        End If
 
        '----------------
 
        If currentValue = "-1" Then
            CurrentFilterFunction = GridKnownFunction.NoFilter
        Else
            CurrentFilterFunction = GridKnownFunction.EqualTo
        End If
 
        Return currentValue
 
    End Function
 
End Class

The class (linq to sql)

<Global.System.Data.Linq.Mapping.TableAttribute(Name:="dbo.Status")>  _
Partial Public Class Status
    Implements System.ComponentModel.INotifyPropertyChanging, System.ComponentModel.INotifyPropertyChanged
     
    Private Shared emptyChangingEventArgs As PropertyChangingEventArgs = New PropertyChangingEventArgs(String.Empty)
     
    Private _StatusID As Integer
     
    Private _Name As String
     
    Private _Red As Integer
     
    Private _Green As Integer
     
    Private _Blue As Integer
     
    Private _SortOrder As Integer
     
    Private _QuoteHistories As EntitySet(Of QuoteHistory)
     
    Private _Quotes As EntitySet(Of Quote)
     
    #Region "Extensibility Method Definitions"
    Partial Private Sub OnLoaded()
    End Sub
    Partial Private Sub OnValidate(action As System.Data.Linq.ChangeAction)
    End Sub
    Partial Private Sub OnCreated()
    End Sub
    Partial Private Sub OnStatusIDChanging(value As Integer)
    End Sub
    Partial Private Sub OnStatusIDChanged()
    End Sub
    Partial Private Sub OnNameChanging(value As String)
    End Sub
    Partial Private Sub OnNameChanged()
    End Sub
    Partial Private Sub OnRedChanging(value As Integer)
    End Sub
    Partial Private Sub OnRedChanged()
    End Sub
    Partial Private Sub OnGreenChanging(value As Integer)
    End Sub
    Partial Private Sub OnGreenChanged()
    End Sub
    Partial Private Sub OnBlueChanging(value As Integer)
    End Sub
    Partial Private Sub OnBlueChanged()
    End Sub
    Partial Private Sub OnSortOrderChanging(value As Integer)
    End Sub
    Partial Private Sub OnSortOrderChanged()
    End Sub
    #End Region
     
    Public Sub New()
        MyBase.New
        Me._QuoteHistories = New EntitySet(Of QuoteHistory)(AddressOf Me.attach_QuoteHistories, AddressOf Me.detach_QuoteHistories)
        Me._Quotes = New EntitySet(Of Quote)(AddressOf Me.attach_Quotes, AddressOf Me.detach_Quotes)
        OnCreated
    End Sub
     
    <Global.System.Data.Linq.Mapping.ColumnAttribute(Storage:="_StatusID", AutoSync:=AutoSync.OnInsert, DbType:="Int NOT NULL IDENTITY", IsPrimaryKey:=true, IsDbGenerated:=true)>  _
    Public Property StatusID() As Integer
        Get
            Return Me._StatusID
        End Get
        Set
            If ((Me._StatusID = value)  _
                        = false) Then
                Me.OnStatusIDChanging(value)
                Me.SendPropertyChanging
                Me._StatusID = value
                Me.SendPropertyChanged("StatusID")
                Me.OnStatusIDChanged
            End If
        End Set
    End Property
     
    <Global.System.Data.Linq.Mapping.ColumnAttribute(Storage:="_Name", DbType:="VarChar(50) NOT NULL", CanBeNull:=false)>  _
    Public Property Name() As String
        Get
            Return Me._Name
        End Get
        Set
            If (String.Equals(Me._Name, value) = false) Then
                Me.OnNameChanging(value)
                Me.SendPropertyChanging
                Me._Name = value
                Me.SendPropertyChanged("Name")
                Me.OnNameChanged
            End If
        End Set
    End Property
     
    <Global.System.Data.Linq.Mapping.ColumnAttribute(Storage:="_Red", DbType:="Int NOT NULL")>  _
    Public Property Red() As Integer
        Get
            Return Me._Red
        End Get
        Set
            If ((Me._Red = value)  _
                        = false) Then
                Me.OnRedChanging(value)
                Me.SendPropertyChanging
                Me._Red = value
                Me.SendPropertyChanged("Red")
                Me.OnRedChanged
            End If
        End Set
    End Property
     
    <Global.System.Data.Linq.Mapping.ColumnAttribute(Storage:="_Green", DbType:="Int NOT NULL")>  _
    Public Property Green() As Integer
        Get
            Return Me._Green
        End Get
        Set
            If ((Me._Green = value)  _
                        = false) Then
                Me.OnGreenChanging(value)
                Me.SendPropertyChanging
                Me._Green = value
                Me.SendPropertyChanged("Green")
                Me.OnGreenChanged
            End If
        End Set
    End Property
     
    <Global.System.Data.Linq.Mapping.ColumnAttribute(Storage:="_Blue", DbType:="Int NOT NULL")>  _
    Public Property Blue() As Integer
        Get
            Return Me._Blue
        End Get
        Set
            If ((Me._Blue = value)  _
                        = false) Then
                Me.OnBlueChanging(value)
                Me.SendPropertyChanging
                Me._Blue = value
                Me.SendPropertyChanged("Blue")
                Me.OnBlueChanged
            End If
        End Set
    End Property
     
    <Global.System.Data.Linq.Mapping.ColumnAttribute(Storage:="_SortOrder", DbType:="Int NOT NULL")>  _
    Public Property SortOrder() As Integer
        Get
            Return Me._SortOrder
        End Get
        Set
            If ((Me._SortOrder = value)  _
                        = false) Then
                Me.OnSortOrderChanging(value)
                Me.SendPropertyChanging
                Me._SortOrder = value
                Me.SendPropertyChanged("SortOrder")
                Me.OnSortOrderChanged
            End If
        End Set
    End Property
     
    <Global.System.Data.Linq.Mapping.AssociationAttribute(Name:="Status_QuoteHistory", Storage:="_QuoteHistories", ThisKey:="StatusID", OtherKey:="StatusID")>  _
    Public Property QuoteHistories() As EntitySet(Of QuoteHistory)
        Get
            Return Me._QuoteHistories
        End Get
        Set
            Me._QuoteHistories.Assign(value)
        End Set
    End Property
     
    <Global.System.Data.Linq.Mapping.AssociationAttribute(Name:="Status_Quote", Storage:="_Quotes", ThisKey:="StatusID", OtherKey:="StatusID")>  _
    Public Property Quotes() As EntitySet(Of Quote)
        Get
            Return Me._Quotes
        End Get
        Set
            Me._Quotes.Assign(value)
        End Set
    End Property
     
    Public Event PropertyChanging As PropertyChangingEventHandler Implements System.ComponentModel.INotifyPropertyChanging.PropertyChanging
     
    Public Event PropertyChanged As PropertyChangedEventHandler Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged
     
    Protected Overridable Sub SendPropertyChanging()
        If ((Me.PropertyChangingEvent Is Nothing)  _
                    = false) Then
            RaiseEvent PropertyChanging(Me, emptyChangingEventArgs)
        End If
    End Sub
     
    Protected Overridable Sub SendPropertyChanged(ByVal propertyName As [String])
        If ((Me.PropertyChangedEvent Is Nothing)  _
                    = false) Then
            RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
        End If
    End Sub
     
    Private Sub attach_QuoteHistories(ByVal entity As QuoteHistory)
        Me.SendPropertyChanging
        entity.Status = Me
    End Sub
     
    Private Sub detach_QuoteHistories(ByVal entity As QuoteHistory)
        Me.SendPropertyChanging
        entity.Status = Nothing
    End Sub
     
    Private Sub attach_Quotes(ByVal entity As Quote)
        Me.SendPropertyChanging
        entity.Status = Me
    End Sub
     
    Private Sub detach_Quotes(ByVal entity As Quote)
        Me.SendPropertyChanging
        entity.Status = Nothing
    End Sub
End Class

Any ideas how I can resolve this issue?



1 Answer, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 17 Feb 2011, 11:34 AM
Hello Modo,

I am sorry to hear that you are having a hard time implementing filtering with different types of controls for your RadGrid for ASP.NET AJAX.

Generally speaking, the filter controls for the grid columns will vary based on their data type as shown in this online demo of the product:

http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/filtering/defaultcs.aspx

Additionally, you have the option to implement your own custom column with filter control of your choice as demonstrates here:

http://demos.telerik.com/aspnet-ajax/grid/examples/programming/filteringtemplatecolumns/defaultcs.aspx

All the best,
Pavlina
the Telerik team
Tags
Grid
Asked by
Modo
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Share this question
or