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
872
set webdatagrid filterrow filter to default to contains
posted

I followed the directions in other posts pertaining to this issue but have not had success.  I would like the default filter in "string" columns to be "contains".  Basically my goal is that when the grid appears the user can double click on the filterrow, enter some text, hit enter, and have the grid rows display the filtered items.   I used the following code in the LOAD event:

   dgTableEdit.ClearDataSource()
   dgTableEdit.Columns.Clear()
   dgTableEdit.DataSource = SqlDataSource_Users
   dgTableEdit.DataBind()

If Not IsPostBack Then
  For i As Integer = 0 To dgTableEdit.Columns.Count - 1
     If dgTableEdit.Columns(i).Type.FullName.ToString.ToUpper = "SYSTEM.STRING" Then
       Dim MyFilter As New Infragistics.Web.UI.GridControls.ColumnFilter
       MyFilter.ColumnKey = dgTableEdit.Columns(i).Key
       MyFilter.Condition = New Infragistics.Web.UI.GridControls.RuleTextNode(Infragistics.Web.UI.GridControls.TextFilterRules.Contains, "")
       dgTableEdit.Behaviors.Filtering.ColumnFilters.Add(MyFilter)
     End If
   Next
Else  'it is a postback
            dgTableEdit.DataSource = SqlDataSource_Users           'datasource declaration reqd on every postback
            '3-4-2020 initialize row filter types
            For i As Integer = 0 To dgTableEdit.Columns.Count - 1
                If dgTableEdit.Columns(i).Type.FullName.ToString.ToUpper = "SYSTEM.STRING" Then
                    Dim MyFilter As New Infragistics.Web.UI.GridControls.ColumnFilter
                    MyFilter.ColumnKey = dgTableEdit.Columns(i).Key
                    MyFilter.Condition = New Infragistics.Web.UI.GridControls.RuleTextNode(Infragistics.Web.UI.GridControls.TextFilterRules.Contains, "")
                    dgTableEdit.Behaviors.Filtering.ColumnFilters.Add(MyFilter)
                End If
            Next
        End If
Endif

I set a breakpoint after this and the columnfilters for my string columns had the filter "contains".  However, when I ran the program and put a value into the filterrow and hit enter, the rows did not filter.  I put a breakpoint into the code after the postback, and the columnfilters for the column was changed to "all". 

Can anybody explain why the filter changed back to "all", and how I can make the filter "contains" stick?   Also, as indicated in code above, I tried putting the code into the "isPostBack" section so that the filter would be set to contains for both the initial load and the postbacks.  But it still did not work.

Any ideas what the issue might be?