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 NextElse '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 IfEndif
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?
Thank you for posting in our community.
From the provided code snippet, it looks like that the "contains" filter is set to an empty string on every postback which in turn clears the previously entered value. By removing the initialization of the filter in the else block, should resolve the issue.
Hi Martin, the initialization of the filter in the ELSE block was not there originally. I put in to see if that would make it work. It didn't so I now took it out.
After some more debugging I found that the code to set the filters was never running because the Columns.Count for the grid was zero.
That explains why the filter is not set, but I'm not sure why the columns.count was zero. Thought it might have to do with the AutoGenerateColumns was set to true and the so I tried it with AutoGenerateColumns set to false. When I did this the webdatagrid (which displayed all the columns properly before) now displayed NO columns and the Columns.count was still zero.
I had set all the columns in using the WebDataGrid Designer:
Now I have no idea why these columns disappeared in the code behind. I also tried with EnableDataViewState to TRUE (it was False) but it still didn't work.
Here is grid with AutoGenerateColumns TRUE
Here is grid with AutoGenerateColumns FALSE
Clearly, I'm missing something basic, but I'm not sure what. I think I'm dealing with two questions. (1) why is my columns.count zero in the code behind? and (2) when AutoGenerateColumns is FALSE why do the columns defined with the WebDataGrid Designer seem to disappear? Any ideas?
Thank you for the detailed explanation.When AutoGenerateColumns property is set to false, the columns object will be empty. This is the default behavior.If you have defined the columns in the markup they should display correctly.
I have created and attached a sample for your reference. Please test it on your side and let me know if it meets your requirements.