Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > Grid > Loop Through The Filter Items on A Grid

Answered Loop Through The Filter Items on A Grid

Feed from this thread
  • Tracy Intermediate avatar

    Posted on Feb 8, 2012 (permalink)

    Hi,

    Can you tell me how to loop through all the filter items on a grid and get the unique name, type and selected value of each item.  I would like to achieve this on a button click.

    For Example,

    Protected

     

    Sub btnSettings_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSettings.Click

     

     

    For Each filterItem As GridFilteringItem In rgvEmployees.MasterTableView.GetItems(GridItemType.FilteringItem)

     

     

    'Loop through each item and get uniquename, type and selectedvalue        

     

     

    Next

     


    Thank you for your help.
    Tracy

    Reply

  • Posted on Feb 8, 2012 (permalink)

    Hello,

    Try the following code.
    VB:
    Protected Sub Button1_Click(sender As Object, e As EventArgs)
        For Each item As GridFilteringItem In RadGrid1.MasterTableView.GetItems(GridItemType.FilteringItem)
            For Each column As GridColumn In RadGrid1.MasterTableView.Columns
                Dim uname As String = column.UniqueName
            Next
        Next
    End Sub

    Thanks,
    Princy.

    Reply

  • Tracy Intermediate avatar

    Posted on Feb 9, 2012 (permalink)

    Hi Princy,

    Thanks for your response. 

    I tried the code you sent and it is not returning the filter columns, it is returning the dataitem columns in the grid.  Can you tell me how to get the filter columns .

    Thank You
    Tracy

    Reply

  • Tsvetoslav Tsvetoslav admin's avatar

    Posted on Feb 10, 2012 (permalink)

    Hi Tracy,

    The columns in the grid are a single set no matter if some of those are filtered on or not. So what you need to do is: while looping through the Columns collection of the grid, check if the columns is a GridBoundColumn (or any other type of column you might have), cast the column to the respective type and inspect its CurrentFilterValue and CurrentFilterFunction properties. If a filter expression is applied on a column, those properties will be set to the values selected.

    Hope it helps.

    Regards,
    Tsvetoslav
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>

    Reply

  • Tracy Intermediate avatar

    Posted on Feb 10, 2012 (permalink)

    Hi Tsvetoslav,

    Based on your post I was able to get the filter columns using the following code
    For Each fltItem As GridFilteringItem In rgvEmployees.MasterTableView.GetItems(GridItemType.FilteringItem)
        For Each column As GridColumn In rgvEmployees.MasterTableView.Columns
            If column.ColumnType = "GridBoundColumn" Or column.ColumnType = "GridTemplateColumn" Then
                If column.ColumnType = "GridBoundColumn" Then
                    strFilterName = column.UniqueName
                ElseIf column.ColumnType = "GridTemplateColumn" Then
                    strFilterName = Right(column.UniqueName, Len(column.UniqueName) - 3)
                End If
                If Not TryCast(fltItem(column.UniqueName).FindControl(strFilterName), RadComboBox) Is Nothing Then
                    Dim rcbFilter As RadComboBox = DirectCast(fltItem(column.UniqueName).FindControl("rcbFilter" + strFilterName), RadComboBox)
                    strFilterFields = strFilterFields + strFilterName + "," + rcbFilter.Text + ";"
                End If
            End If
        Next
    Next

    But I should have been more clear on what I am trying to do.  I have filter templates on each of my columns in my grid and I am trying to loop through all the columns on the grid and determine if the column has a filter template associated with it.  If it does I would like to retrieve the control within the filter template and get its unique name, text value, selected index, type of control.  I want to be able to do this without knowing what the unique name of the filter template is.
    Tracy 

    Reply

  • Tsvetoslav Tsvetoslav admin's avatar

    Posted on Feb 13, 2012 (permalink)

    Hi Tracy,

    I could not understand from your last ticket if you have managed to fulfill your requirement. Going by your code snippet your approach is the right one.

    Regards,
    Tsvetoslav
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>

    Reply

  • Tracy Intermediate avatar

    Posted on Feb 13, 2012 (permalink)

    Hi Tsvetoslav,

    Actually my question hasn't been answered,  I should have been more clear on what I am trying to do.  I have filter templates on each of my columns in my grid and I am trying to loop through all the columns on the grid and determine if the column has a filter template associated with it.  If it does I would like to retrieve the control within the filter template and get its unique name, text value, selected index, type of control.  I want to be able to do this without knowing what the unique name of the filter template is.


    Thank you for your assistance.

    Tracy

    Reply

  • Tsvetoslav Tsvetoslav admin's avatar

    Posted on Feb 13, 2012 (permalink)

    Hi Tracy,

    In you case, you should check the columns' FilterTemplate property if it is null or not and if not, retrieve the filter control through the FindControl method using the approach you have already taken.

    Greetings,
    Tsvetoslav
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>

    Reply

  • Tracy Intermediate avatar

    Posted on Feb 13, 2012 (permalink)

    Hi Tsvetoslav,

    I can loop through the columns and find the ones with a filter template but your suggestion on using the Find Control method is working because the find control method requires that I know the unique name of the filter column.  One of the values I am trying to get is the unique name of the filter template.  I want to be able to loop through the controls and retrieve the unique name of the control in the filter template.

    Thank You

    Reply

  • Tsvetoslav Tsvetoslav admin's avatar

    Posted on Feb 16, 2012 (permalink)

    Hi Tracy,

    I am confused on what you are trying to achieve. Anyhow, if you need to loop through the controls in the filter template, just loop through the Controls collection of the filter cell. And the filter cell you get by indexing into the filter item by unique column name.

    Regards, Tsvetoslav
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>

    Reply

  • Tracy Intermediate avatar

    Posted on Feb 16, 2012 (permalink)

    Hi Tsvetoslav,

    Can you show me the code I would use to loop through the filter cells as you are suggesting below.

    Thank You

    Reply

  • Answer Tsvetoslav Tsvetoslav admin's avatar

    Posted on Feb 21, 2012 (permalink)

    Hi Tracy,

    Attached is a small sample.

    All the best,
    Tsvetoslav
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
    Attached files

    Reply

  • Tracy Intermediate avatar

    Posted on Feb 21, 2012 (permalink)

    Hi  Tsvetoslav,

    Thank you for the sample project but this is not solving my problem. Your solution assumes that I know the unique name of the filter template.  I want to be able to loop through the filter templates and retrieve the unique name.

    Thanks

    Tracy

    Reply

  • Tsvetoslav Tsvetoslav admin's avatar

    Posted on Feb 24, 2012 (permalink)

    Hello Tracy,

    I don't see how I use the name of the template anywhere in my code - all I have employed is the ID of the combo box within the template. However, you don't need to know this as well and that's why I added the following comment below the statements that get hold of the combo box object:

    //NB: Besides, filterItem[column.UniqueName].Controls will give you access to all the controls rendered by the filter template of the column

    This means that by iterating through the Controls collection mentioned above you can get reference of the controls required.

    Greetings,
    Tsvetoslav
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.

    Reply

  • Tracy Intermediate avatar

    Posted on Feb 25, 2012 (permalink)

    Hi Tsvetoslav,

    Thank you for the sample.   I tried converting the code to VB through Telerik's code converter and it wouldn't work therefore I converted it to VB myself and converted it incorrectly and therefore misread the code.  I have since successfully converted the code to VB and now have an understanding of what you were showing me in the sample you provided.

    Your sample provided me with the solution I was looking for.

    Thank you for your assistance.

    Tracy

    Reply

  • Answer Tsvetoslav Tsvetoslav admin's avatar

    Posted on Feb 29, 2012 (permalink)

    Hi Tracy,

    You are welcome. Good luck with your development.


    All the best, Tsvetoslav
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.

    Reply

  • Say Hello to Telerik's PivotGrid for ASP.NET AJAX, Silverlight, WPF and WinForms. Now packed with OLAP support.

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > Grid > Loop Through The Filter Items on A Grid
Related resources for "Loop Through The Filter Items on A Grid"

ASP.NET Grid Features  |  Documentation  |  Demos  |  Step-by-step Tutorial  ]