Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
115
How to apply filter at runtime in WHDG 11.2
posted

Hello.

 

I'm currently trying to apply a filter at runtime, using code-behind or in aspx.

 

This is how I'm coding in the aspx:

<ig:Filtering EnableInheritance="True">

                <ColumnSettings>

                    <ig:ColumnFilteringSetting ColumnKey="Ano" />

                </ColumnSettings>

                <ColumnFilters>

                    <ig:ColumnFilter ColumnKey="Ano">

                    <ConditionWrapper>

                        <ig:RuleNumberNode Value="2012" />

                    </ConditionWrapper>

                    </ig:ColumnFilter>

                </ColumnFilters>

            </ig:Filtering>

 

And this is what I've been trying at the code-behind.

 

Private Sub GridNecessidadesRegaAnual_InitializeBand(sender As Object, e As Infragistics.Web.UI.GridControls.BandEventArgs) Handles GridNecessidadesRegaAnual.InitializeBand

        Dim columnFilter As New ColumnFilter

        Dim filtering As Filtering

        filtering = Me.GridNecessidadesRegaAnual.Bands(0).Behaviors.Filtering

        columnFilter.ColumnKey = "Ano"

        columnFilter.Condition = New RuleNumberNode(TextFilterRules.Equals, 2012)

        filtering.ColumnFilters.Add(columnFilter)

 

        filtering.ApplyFilter()

    End Sub

 

None of them seemed to work. The aspx code is just simply not working, the column shows with the filter, but it does nothing more. The code-behind gets me an error "Object reference not set to an instance of an object."

Can you help me, please?

Thanks

Parents
No Data
Reply
  • 115
    Verified Answer
    posted

    Well, it seems that I managed to get it done using this code in the page load handler

     

     

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Not IsPostBack then        

               Dim columnfilter As ColumnFilter

              columnfilter = New ColumnFilter(Me.GridNecessidadesRegaAnual.GridView)

               columnfilter.ColumnKey = "Ano"

               columnfilter.Condition = New RuleNumberNode(TextFilterRules.Equals, 2012)

               Me.GridNecessidadesRegaAnual.GridView.Behaviors.Filtering.ColumnFilters.Add(columnfilter)

            End If

        End Sub

     

    I used a code sample that I found in InfragisticsNAforASPNETGridCheatSheet.pdf, but the same document refers two other code samples, one using the initializeband event and one other using the rowislandcreated event. None of them worked.

     

Children
No Data