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

Custom Filter

3 Answers 37 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 28 Aug 2014, 06:49 AM
Hello,

I am working on a project with a RadGrid.
I need to make a custom filter.
I read your documentation and saw the instructions how to do it.

My problem is that the code works only for string type filters.
I get the following error in line 08 when I try to filter other types:

Unable to cast object of type 'Telerik.Web.UI.RadNumericTextBox'
to type 'System.Web.UI.WebControls.TextBox'.

My grid is generic (columns and data fields types are changed dynamically in run-time). 

VB.NET Code:
01.Private Sub RadGrid1_ItemCommand(sender As Object, e As GridCommandEventArgs) Handles RadGrid1.ItemCommand
02.  
03.  
04.        If e.CommandName = RadGrid.FilterCommandName Then
05.            Dim filterPair As Pair = CType(e.CommandArgument, Pair)
06.            Dim filteritem = (CType(e.Item, GridFilteringItem))
07.  
08.            Dim textBox As TextBox = CType(filteritem(filterPair.Second.ToString()).Controls(0), TextBox)
09.            'Dim textBox As CheckBox = CType(x(filterPair.Second.ToString()).Controls(0), CheckBox)
10.            'Dim textBox As RadNumericTextBox = CType(x(filterPair.Second.ToString()).Controls(0), RadNumericTextBox)
11.            'Dim textBox As RadDatePicker = CType(x(filterPair.Second.ToString()).Controls(0), RadDatePicker)
12.  
13.            Dim val As String = textBox.Text
14.            Select Case filterPair.First
15.                Case "EqualTo"
16.  
17.                    'some logic
18.  
19.  
20.                Case ""
21.            End Select
22.  
23.             
24.            e.Canceled = True
25.  
26.  
27.        End If
28.    End Sub


Thank you,
Daniel

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 28 Aug 2014, 07:18 AM
Hi Daniel,

You are getting the following error because you are trying to access a numeric column's filter textbox which is a RadNumericTextBox, hence you can't access it using TextBox. You can loop through the columns and get the type of column and assign each textbox according to the type.

Thanks,
Shinu
0
Daniel
Top achievements
Rank 1
answered on 01 Sep 2014, 09:38 AM
Hello Shinu,

Thank you for your answer.

I have applied it in my project and it works!

In my project I have columns of DateTime type. On these columns there is a RangeFilter.
RadGrid identifies the RangeFilter values as LiteralControl type. How can I convert this into DateTime?

 
Thanks, 
Daniel.
0
Eyup
Telerik team
answered on 03 Sep 2014, 03:44 PM
Hello Daniel,

Once you access the LiteralControl, you can DateTime.Parse its Text value:
http://www.telerik.com/forums/basic-filtering-datetime-range#J6au2nck4EKUQCxcC-8u9g

Hope this helps.

Regards,
Eyup
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Daniel
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Daniel
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or