I am following this example in the RadGrid(filtering - how to) documentation.
Filtering with MS DropDownList instead of textbox.
-----------------------------------------------------------------------------------------------------------------------------------
I have a page(sample.aspx.vb) where i am displaying the radgrid with,
AllowFilteringByColumn
="True"
I would like to replace a filter textbox with a dropdown list which has two options (YES/NO) for a specific column.
Say column "A" only has values, YES or NO. So i would like to display these options in a dropdownlist.
I have copied the below code(given in the example) in my (sample.aspx.vb) at the end of class [Class sample].
-----------------------------------------------------------------------------------------
Namespace MyStuff
Public Class MyCustomFilteringColumn
Inherits GridBoundColumn
Private listDataSource As Object = Nothing
'RadGrid calls this method when it initializes the controls inside the filtering item cells
Protected Overloads Overrides Sub SetupFilterControls(ByVal cell As TableCell)
MyBase.SetupFilterControls(cell)
cell.Controls.RemoveAt(0)
Dim list As New DropDownList()
list.ID = "list" + Me.DataField
list.Height = Unit.Pixel(300)
list.AutoPostBack = True
AddHandler list.SelectedIndexChanged, AddressOf list_SelectedIndexChanged
cell.Controls.AddAt(0, list)
cell.Controls.RemoveAt(1)
list.DataTextField = Me.DataField
list.DataValueField = Me.DataField
list.DataSource = Me.ListDataSource
list.DataBind()
End Sub
Sub list_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim filterItem As GridFilteringItem = TryCast((TryCast(sender, DropDownList)).NamingContainer, GridFilteringItem)
If Me.DataType = GetType("System.Int32") OrElse Me.DataType = GetType("System.Int16") OrElse Me.DataType = GetType("System.Int64") Then
filterItem.FireCommandEvent("Filter", New Pair("EqualTo", Me.UniqueName))
Else
filterItem.FireCommandEvent("Filter", New Pair("Contains", Me.UniqueName))
' treat everything else like a string
End If
End Sub
Public Property ListDataSource() As Object
Get
Return Me.listDataSource
End Get
Set
listDataSource = value
End Set
End Property
'RadGrid calls this method when the value should be set to the filtering input control(s)
Protected Overloads Overrides Sub SetCurrentFilterValueToControl(ByVal cell As TableCell)
MyBase.SetCurrentFilterValueToControl(cell)
Dim list As DropDownList = DirectCast(cell.Controls(0), DropDownList)
If Me.CurrentFilterValue <> String.Empty Then
list.SelectedValue = Me.CurrentFilterValue
End If
End Sub
'RadGrid calls this method to extract the filtering value from the filtering input control(s)
Protected Overloads Overrides Function GetCurrentFilterValueFromControl(ByVal cell As TableCell) As String
Dim list As DropDownList = DirectCast(cell.Controls(0), DropDownList)
Return list.SelectedValue
End Function
Protected Overloads Overrides Function GetFilterDataField() As String
Return Me.DataField
End Function
End Class
End Namespace
---------------------------
1. i get the following errors at these lines.
a.
If Me.DataType = GetType("System.Int32") OrElse Me.DataType = GetType("System.Int16") OrElse Me.DataType = GetType("System.Int64") Then
At this statement - GetType
("System.Int32") ---- type expected
b.
Public Property ListDataSource() As Object
'ListDataSource' is already declared as 'Private Dim lstDataSource As Object' in this class.
I have all the required imports statements.
Did anyone had such problems before, how should i fix these errors
2. Do i need to create another class(.vb) file and put all this code.
Need some help.
Thank you,
tyra