Solution for Infragistics WebDataGrid filtering error “Length cannot be less than zero”

Infragistics WebDataGrid/WHDG controls for ASP.NET offer nice filtering features. Out of the box you just have to enable the behavior and badabingo:

WebDataGrid filtering

There is one glitch though in the way text filtering is implemented: If you enter an empty string as a filter value – an error is thrown:

Async refresh failed. Length cannot be less than zero

Apparently internal grid code cannot handle empty strings (as of version 12.2) so we have to take matter in our own hands.

Add following code to your grid’s DataFiltering event handler:

Protected Sub xMyGrid_DataFiltering(sender As Object, e As GridControls.FilteringEventArgs) Handles xMyGrid.DataFiltering

    For I As Integer = e.ColumnFilters.Count - 1 To 0 Step -1
        If e.ColumnFilters(I).ColumnType = "string" Then
            If DirectCast(e.ColumnFilters(I).Condition, GridControls.RuleTextNode).Value = "" Then
            End If
        End If

    'rebind the grid to datasource as needed
End Sub

Essentially what is happening here – we loop thru all column filters, check if it’s a text column and if it is – check its filter ‘s value. If it’s an empty string – we simple removing the filter from the collection. Error is gone, filter is performed as expected.

One reply

  1. This issue is resolved in the latest service release so an alternative to your workaround would be to download the latest service release from the My Keys and Downloads page:

    Note that to download the service release you must have your NetAdvantage key registered to your profile. You could also install the service release using the platform installer when installing NetAdvantage for ASP.NET.

Leave a Reply

Your email address will not be published. Required fields are marked *