I have used this solution from http://www.devexpress.com/Support/Center/p/Q109328.aspx to preset all filter AutoFilterCondition to "Contains".
However, if you field is an integer, the "Contains" is not a valid filter option, and if the integer column is filtered upon, no results are returned.
How can I only apply "Contains" to the AutoFilterCondition for only the field types that have this option?
protected void Page_Load(object sender, EventArgs e) {
if (!IsPostBack)
foreach (GridViewColumn col in ASPxGridView1.Columns)
if (col is GridViewDataColumn)
((GridViewDataColumn)col).Settings.AutoFilterCondition = AutoFilterCondition.Contains;
}
ASPxGridView - Change default value of Filter Row condition
Answers approved by DevExpress Support
Hello Scott,
Thank you for your reply.
Usually it is known what type column data items have. You can check the column's FieldName property and initialize the AutoFilterCondition setting only for necessary columns.
If you need to check a data item's type at runtime, you need to use the ASPxClientGridView.GetRowValues method:
C#protected void Page_Load(object sender, EventArgs e) {
if (!IsPostBack)
foreach (GridViewColumn col in grid.Columns) {
GridViewDataColumn c = col as GridViewDataColumn;
if ((c != null)
&& !(c.Grid.GetRowValues(0, c.FieldName) is int)) {
c.Settings.AutoFilterCondition = AutoFilterCondition.Contains;
}
}
}
If you have any other questions, please contact us at any time.
Updated, Owner's solution:
Here is a VB version in case anyone needs.
This sub is ran on initial Page_Load event.
Public Sub SetGridViewFilterModeToContains(ByVal gv As ASPxGridView)
For Each col As GridViewColumn In gv.Columns
Dim c As GridViewDataColumn = TryCast(col, GridViewDataColumn)
If (c IsNot Nothing) AndAlso Not (TypeOf c.Grid.GetRowValues(0, c.FieldName) Is Integer) Then
c.Settings.AutoFilterCondition = AutoFilterCondition.Contains
End If
Next
End Sub
Your solution worked great. thanks!
Here is a VB version in case anyone needs.
This sub is ran on initial Page_Load event.
Public Sub SetGridViewFilterModeToContains(ByVal gv As ASPxGridView)
For Each col As GridViewColumn In gv.Columns
Dim c As GridViewDataColumn = TryCast(col, GridViewDataColumn)
If (c IsNot Nothing) AndAlso Not (TypeOf c.Grid.GetRowValues(0, c.FieldName) Is Integer) Then
c.Settings.AutoFilterCondition = AutoFilterCondition.Contains
End If
Next
End Sub
Hello Scott,
I am glad to hear that our solution meets your requirement. I also appreciate your feedback that can be useful for other users.
If you encounter any difficulty using our components, feel free to contact us at any time.
Best regards,
Vladimir
Hello Scott:
The ASPxGridView control does not provide a property or method that allows checking which filter conditions are acceptable for this column. It depends on the column's data type.
I assume that you can set the initial AutoFilterCondition to Equals for all columns in the grid, retrieve columns which have string data from the Columns collection by their FieldNames and set the AutoFilterCondition to Contains for these columns only.
Thanks
Kate.
I agree Kate,
Within the gridview column loop, how can I determine the column's data type? that is the syntax I am having problems with.