In this example, the CriteriaColumnAffinityResolver.SplitByColumns method is used to return a dictionary of criteria operators. You can modify these criteria operators as required. Please refer to the following GitHub example for more information: Grid for ASP.NET Web Forms - How to programmatically change a column’s filter criterion in the grid’s filter expression.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function OnClick(s, e) {
cardview.PerformCallback();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<dx:ASPxCardView ID="ASPxCardView1" ClientInstanceName="cardview" AutoGenerateColumns="False" DataSourceID="AccessDataSource1" KeyFieldName="ProductID" OnCustomCallback="ASPxCardView1_CustomCallback" runat="server">
<Settings ShowFilterBar="Visible" />
<Columns>
<dx:CardViewTextColumn FieldName="ProductID" ReadOnly="True" VisibleIndex="0">
</dx:CardViewTextColumn>
<dx:CardViewTextColumn FieldName="ProductName" VisibleIndex="1">
</dx:CardViewTextColumn>
<dx:CardViewTextColumn FieldName="CategoryID" VisibleIndex="2">
</dx:CardViewTextColumn>
<dx:CardViewTextColumn FieldName="QuantityPerUnit" VisibleIndex="3">
</dx:CardViewTextColumn>
<dx:CardViewTextColumn FieldName="UnitPrice" VisibleIndex="4">
</dx:CardViewTextColumn>
<dx:CardViewTextColumn FieldName="UnitsInStock" VisibleIndex="5">
</dx:CardViewTextColumn>
</Columns>
</dx:ASPxCardView>
<table>
<tr>
<td>Filter by:
</td>
<td>
<dx:ASPxComboBox ID="ASPxComboBox1" runat="server" ValueType="System.String">
<Items>
<dx:ListEditItem Value="ProductID" />
<dx:ListEditItem Value="ProductName" />
<dx:ListEditItem Value="CategoryID" />
<dx:ListEditItem Value="QuantityPerUnit" />
<dx:ListEditItem Value="UnitPrice" />
<dx:ListEditItem Value="UnitsInStock" />
</Items>
</dx:ASPxComboBox>
</td>
<td>
<dx:ASPxTextBox ID="ASPxTextBox1" runat="server" Width="170px">
</dx:ASPxTextBox>
</td>
<td>
<dx:ASPxButton ID="ASPxButton1" runat="server" Text="Filter" AutoPostBack="false">
<ClientSideEvents Click="OnClick" />
</dx:ASPxButton>
</td>
</tr>
</table>
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/Categories + products.mdb" SelectCommand="SELECT [ProductID], [ProductName], [CategoryID], [QuantityPerUnit], [UnitPrice], [UnitsInStock] FROM [Products]"></asp:AccessDataSource>
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DevExpress.Data.Filtering;
using DevExpress.Web;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e) {
}
protected void ASPxCardView1_CustomCallback(object sender, DevExpress.Web.ASPxCardViewCustomCallbackEventArgs e) {
ASPxCardView grid = sender as ASPxCardView;
ModifyFilterExpression(ASPxComboBox1.Value.ToString(), ASPxTextBox1.Value, grid);
}
protected void ModifyFilterExpression(string FieldName, object value, ASPxCardView victim) {
var criterias = CriteriaColumnAffinityResolver.SplitByColumnNames(CriteriaOperator.Parse(victim.FilterExpression)).Item2;
BinaryOperatorType operatorType;
if (FieldName == "ProductName")
{
operatorType = BinaryOperatorType.Like;
value += "%";
}
else
operatorType = BinaryOperatorType.Equal;
if (!criterias.Keys.Contains(FieldName))
criterias.Add(FieldName, new BinaryOperator(FieldName, value, operatorType));
else
criterias[FieldName] = new BinaryOperator(FieldName, value, operatorType);
victim.FilterExpression = CriteriaOperator.ToString(GroupOperator.And(criterias.Values));
}
}
Option Infer On
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports DevExpress.Data.Filtering
Imports DevExpress.Web
Partial Public Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
End Sub
Protected Sub ASPxCardView1_CustomCallback(ByVal sender As Object, ByVal e As DevExpress.Web.ASPxCardViewCustomCallbackEventArgs)
Dim grid As ASPxCardView = TryCast(sender, ASPxCardView)
ModifyFilterExpression(ASPxComboBox1.Value.ToString(), ASPxTextBox1.Value, grid)
End Sub
Protected Sub ModifyFilterExpression(ByVal FieldName As String, ByVal value As Object, ByVal victim As ASPxCardView)
Dim criterias = CriteriaColumnAffinityResolver.SplitByColumnNames(CriteriaOperator.Parse(victim.FilterExpression)).Item2
Dim operatorType As BinaryOperatorType
If FieldName = "ProductName" Then
operatorType = BinaryOperatorType.Like
value &= "%"
Else
operatorType = BinaryOperatorType.Equal
End If
If Not criterias.Keys.Contains(FieldName) Then
criterias.Add(FieldName, New BinaryOperator(FieldName, value, operatorType))
Else
criterias(FieldName) = New BinaryOperator(FieldName, value, operatorType)
End If
victim.FilterExpression = CriteriaOperator.ToString(GroupOperator.And(criterias.Values))
End Sub
End Class
<%@ Page Language="vb" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function OnClick(s, e) {
cardview.PerformCallback();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<dx:ASPxCardView ID="ASPxCardView1" ClientInstanceName="cardview" AutoGenerateColumns="False" DataSourceID="AccessDataSource1" KeyFieldName="ProductID" OnCustomCallback="ASPxCardView1_CustomCallback" runat="server">
<Settings ShowFilterBar="Visible" />
<Columns>
<dx:CardViewTextColumn FieldName="ProductID" ReadOnly="True" VisibleIndex="0">
</dx:CardViewTextColumn>
<dx:CardViewTextColumn FieldName="ProductName" VisibleIndex="1">
</dx:CardViewTextColumn>
<dx:CardViewTextColumn FieldName="CategoryID" VisibleIndex="2">
</dx:CardViewTextColumn>
<dx:CardViewTextColumn FieldName="QuantityPerUnit" VisibleIndex="3">
</dx:CardViewTextColumn>
<dx:CardViewTextColumn FieldName="UnitPrice" VisibleIndex="4">
</dx:CardViewTextColumn>
<dx:CardViewTextColumn FieldName="UnitsInStock" VisibleIndex="5">
</dx:CardViewTextColumn>
</Columns>
</dx:ASPxCardView>
<table>
<tr>
<td>Filter by:
</td>
<td>
<dx:ASPxComboBox ID="ASPxComboBox1" runat="server" ValueType="System.String">
<Items>
<dx:ListEditItem Value="ProductID" />
<dx:ListEditItem Value="ProductName" />
<dx:ListEditItem Value="CategoryID" />
<dx:ListEditItem Value="QuantityPerUnit" />
<dx:ListEditItem Value="UnitPrice" />
<dx:ListEditItem Value="UnitsInStock" />
</Items>
</dx:ASPxComboBox>
</td>
<td>
<dx:ASPxTextBox ID="ASPxTextBox1" runat="server" Width="170px">
</dx:ASPxTextBox>
</td>
<td>
<dx:ASPxButton ID="ASPxButton1" runat="server" Text="Filter" AutoPostBack="false">
<ClientSideEvents Click="OnClick" />
</dx:ASPxButton>
</td>
</tr>
</table>
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/Categories + products.mdb" SelectCommand="SELECT [ProductID], [ProductName], [CategoryID], [QuantityPerUnit], [UnitPrice], [UnitsInStock] FROM [Products]"></asp:AccessDataSource>
</div>
</form>
</body>
</html>