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

[Solved] Radgrid - combination of google like custom filters

1 Answer 118 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jae Hong
Top achievements
Rank 1
Jae Hong asked on 09 Apr 2013, 05:29 PM
 I am following an example of RadGrid - Google like filtering and have a problem with getting other combobox values that user already chosen.

In the demo grid, after I select "USA" in the country filter, I  would like to set list of cities and postal codes only for "USA"
I already created session state and use them now, but I am wondering whether there is another way to get values from page to MyCustomFilteringColumnVB.vb??


1 Answer, 1 is accepted

Sort by
0
Jae Hong
Top achievements
Rank 1
answered on 10 Apr 2013, 08:12 PM
I finally found a solution to access ViewState in 'list_ItemsRequested' event function.

Based on RadGrid Google-style filtering Demo, I want to make cascaded filtering. For instance, if user choose the first filter item, other filter items that belong to result of the first filtering should be listed.

Here is what I changed session state with view state.

1. create a session class
<Serializable()> _
Public Class UserSessions
    Public sesTest1 As String
    Public sesTest2 As String
    Public sesTest3 As String
End Class

2. Initialize class and assign it to view state
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If Not Page.IsPostBack Then
       Dim US As New UserSessions
       US.sesTest1 = intValue.ToString
       US.sesTest2 = test_val1
       US.sesTest3 = test_val2
       ViewState("sesParam") = US
    End If
   ...
   ...
End Sub

3. Get values from view state in "Public Class rgCustomFilteringColumn"
Imports Telerik.Web.UI
Imports System.Data
Imports System.Reflection
 
Public Class rgMTRSCustomFilteringColumn
    Inherits GridBoundColumn
 
    Protected Sub list_ItemsRequested(ByVal o As Object, ByVal e As RadComboBoxItemsRequestedEventArgs)
        Dim US As UserSessions = GetUSViewStateData()
        Dim strTest1 AS String = DirectCast(DirectCast(DirectCast(o, RadComboBox).Parent.Parent, GridFilteringItem).Cells.Item(2).Controls(0), RadComboBox).Text
        Dim strTest2 AS String = DirectCast(DirectCast(DirectCast(o, RadComboBox).Parent.Parent, GridFilteringItem).Cells.Item(3).Controls(0), RadComboBox).Text
        Dim strTest3 AS String = DirectCast(DirectCast(DirectCast(o, RadComboBox).Parent.Parent, GridFilteringItem).Cells.Item(4).Controls(0), RadComboBox).Text
 
        'So you get all values from ViewState as well as text values from other comboboxes
        ' Now you can create a cascaded sql query
    End Sub
 
    Private Function GetUSViewStateData() As UserSessions
        Dim retval As UserSessions = Nothing
 
        Dim page As Page = DirectCast(HttpContext.Current.CurrentHandler, Page)
        Dim type As Type = GetType(Page)
        Dim flags As BindingFlags = BindingFlags.GetProperty Or BindingFlags.Instance Or BindingFlags.NonPublic
        Dim viewState As UserSessions = TryCast(type.InvokeMember("ViewState", flags, Nothing, page, Nothing), StateBag).Item("sesParam")
        If viewState IsNot Nothing Then retval = viewState
 
        Return retval
    End Function
End Class


Tags
Grid
Asked by
Jae Hong
Top achievements
Rank 1
Answers by
Jae Hong
Top achievements
Rank 1
Share this question
or