ASPxDashboard.CustomFilterExpression Event
Allows you to include WHERE clauses into DashboardSqlDataSource queries.
Namespace: DevExpress.DashboardWeb
Assembly: DevExpress.Dashboard.v24.2.Web.WebForms.dll
Declaration
Event Data
The CustomFilterExpression event's data class is CustomFilterExpressionWebEventArgs. The following properties provide information specific to this event:
Property | Description |
---|---|
DashboardId | Gets the identifier of the current dashboard. |
DataSourceComponentName | Get the data source name, used in code to identify the data source’s object, for which the event has been raised. Inherited from CustomFilterExpressionEventArgs. |
DataSourceConnectionName | Inherited from CustomFilterExpressionEventArgs. |
DataSourceName | Gets the name of the data source for which the event has been raised. Inherited from CustomFilterExpressionEventArgs. |
FilterExpression | Gets or sets the filter expression that defines a WHERE clause included in the SQL query. Inherited from CustomFilterExpressionEventArgs. |
QueryName | Gets the name of the query for which the event was raised. Inherited from CustomFilterExpressionEventArgs. |
Remarks
The CustomFilterExpression
event fires for each SelectQuery within the SqlDataSource.Queries collection. The e.FilterExpression property allows you to include a WHERE clause into a query at runtime. If a filter is already applied to the SQL query, e.FilterExpression
returns the corresponding filter criteria.
For more information on how to create filter criteria as a CriteriaOperator object, refer to the following help article: Simplified Criteria Syntax.
Note
The CustomFilterExpression event is not raised for custom SQL queries and stored procedures.
Example
The following example shows how to filter an SQL query at runtime. To do this, handle the ASPxDashboard.CustomFilterExpression
event:
- e.QueryName
- Checks the name of the query that should be filtered.
- e.FilterExpression
- Specifies the filter criteria.
This example filters the Invoices query with the following expression: “Customers.CompanyName” equals “Around the Horn”.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="ASPxDashboard_CustomFilterExpression.WebForm1" %>
<!DOCTYPE html>
<html>
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div style="position: absolute; top: 0; left: 0; right: 0; bottom: 0;">
<dx:ASPxDashboard ID="ASPxDashboard1" runat="server" Width="100%" Height="100%"
OnCustomFilterExpression="ASPxDashboard1_CustomFilterExpression"
WorkingMode="Viewer">
</dx:ASPxDashboard>
</div>
</form>
</body>
</html>
using System;
using DevExpress.DashboardWeb;
using DevExpress.Data.Filtering;
namespace ASPxDashboard_CustomFilterExpression {
public partial class WebForm1 : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
ASPxDashboard1.SetDashboardStorage(new DashboardFileStorage("~/App_Data/Dashboards"));
}
protected void ASPxDashboard1_CustomFilterExpression(object sender, CustomFilterExpressionWebEventArgs e) {
if (e.DataSourceConnectionName == "nwindConnection" && e.QueryName == "Invoices") {
e.FilterExpression = new BinaryOperator("Customers.CompanyName", "Around the Horn", BinaryOperatorType.Equal);
}
}
}
}