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

Custom column class that replaces the filter text box with a drop-down list in a RadGrid

1 Answer 123 Views
Grid
This is a migrated thread and some comments may be shown as answers.
xyz
Top achievements
Rank 1
xyz asked on 19 Feb 2009, 09:16 PM
Hello,
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

1 Answer, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 23 Feb 2009, 02:14 PM
Hi,

In the latest version of the control, you can take advantage of the newest enhancement of the control, allowing you to provide a filter template for the grid.
I hope this gets you started properly.

Kind regards,
Yavor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
xyz
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Share this question
or