The answer per DevExpress is that the correct FilterExpression is updated when it is databound.
They allege that in BeforePerformDataSelect, you will see the correct value.
I have 1 grid that is hooked up to a SqlDataSource that is correctly doing this, and another that is not... So you're mileage may vary.
My second grid wasn't obeying this principal, so I integrated the other guy's concept rebinding in AfterPerformCallback(). The trick is to prevent double querying. This code also demonstrates how to hijack devexpress to build your own SQL. Obviously, this is from my working project, so use your imagination on functions that I have that you don't...
Here is the relevant html and code:
<dxwgv:ASPxGridView ID="grid" runat="server"
KeyFieldName="OrderID"
OnAfterPerformCallback="grid_AfterPerformCallback"
OnBeforePerformDataSelect="grid_BeforePerformDataSelect"
AutoGenerateColumns="True"
SettingsDetail-AllowOnlyOneMasterRowExpanded="true"
Settings-ShowFilterRow="true"
Settings-ShowFilterRowMenu="True"
SettingsBehavior-AllowSelectSingleRowOnly="true"
OnDetailRowExpandedChanged="Grid_DetailRowExpandedChanged"
Styles-Cell-Cursor="pointer"
SettingsBehavior-EnableRowHotTrack="true"
CssFilePath="~/App_Themes/Office2010Blue/{0}/styles.css"
CssPostfix="Office2010Blue"
SettingsPager-PageSize="<%# this._GridRowsPerPage %>"
SettingsBehavior-ColumnResizeMode="Control"
SettingsCustomizationWindow-PopupHorizontalAlign="WindowCenter"
SettingsCustomizationWindow-PopupVerticalAlign="WindowCenter"
SettingsCustomizationWindow-Width="300px"
Settings-ShowHorizontalScrollBar="true"
Width="<%# this._GetWidth() %>"
SettingsPager-AlwaysShowPager="true"
SettingsCookies-Enabled="true"
>
<Columns>
<dxwgv:GridViewDataColumn FieldName="PriorityType" Visible="false" />
<dxwgv:GridViewDataColumn FieldName="basePatientID" Caption="PTID" />
<dxwgv:GridViewDataColumn FieldName="FirstName" />
<dxwgv:GridViewDataColumn FieldName="LastName" />
<dxwgv:GridViewDataColumn FieldName="Employer" />
<dxwgv:GridViewDataColumn FieldName="Insurer" />
<dxwgv:GridViewDataColumn FieldName="ClaimJurisdiction" Caption="Jurisdiction" />
<dxwgv:GridViewDataColumn FieldName="DOB" Visible="false" />
<dxwgv:GridViewDataColumn FieldName="DateOfInjury" Caption="DOI" Visible="false" />
<dxwgv:GridViewDataColumn FieldName="PostalCode" Caption="ZipCode" Visible="false" />
<dxwgv:GridViewDataColumn FieldName="FirstCareDate" Visible="false" />
<dxwgv:GridViewDataColumn FieldName="LastCareDate" Visible="false" />
<dxwgv:GridViewDataColumn FieldName="IntakeStatus" />
<dxwgv:GridViewDataColumn FieldName="SchedulingNeeded" />
<dxwgv:GridViewDataColumn FieldName="InitialReferralDate" Caption="Date Assigned" />
<dxwgv:GridViewDataColumn FieldName="Orders_UpdatedOn" Caption="Last Follow-up" />
<dxwgv:GridViewDataColumn FieldName="RequestTypes" Caption="Service" Visible="false" />
<dxwgv:GridViewDataColumn FieldName="FacilityGroups" Caption="Provider" Visible="false" />
<dxwgv:GridViewDataColumn FieldName="ICD9Codes" Visible="false" />
<dxwgv:GridViewDataColumn FieldName="CPTCodes" Visible="false" />
<dxwgv:GridViewDataColumn FieldName="OrderCategory" Caption="Source" />
<dxwgv:GridViewDataColumn FieldName="CaseCoordinator" Visible="false" />
<dxwgv:GridViewDataColumn FieldName="SchedulingTier" Visible="false" Caption="Tier" />
<dxwgv:GridViewDataColumn FieldName="LockRequest_UserName" Visible="true" Caption="InUseBy" />
</Columns>
<Styles CssFilePath="~/App_Themes/Office2010Blue/{0}/styles.css" CssPostfix="Office2010Blue">
<Header ImageSpacing="5px" SortingImageSpacing="5px">
</Header>
<LoadingPanel ImageSpacing="10px">
</LoadingPanel>
</Styles>
<ImagesFilterControl>
<LoadingPanel Url="~/App_Themes/Office2010Blue/Editors/Loading.gif">
</LoadingPanel>
</ImagesFilterControl>
<Images SpriteCssFilePath="~/App_Themes/Office2010Blue/{0}/sprite.css">
<LoadingPanelOnStatusBar Url="~/App_Themes/Office2010Blue/GridView/gvLoadingOnStatusBar.gif">
</LoadingPanelOnStatusBar>
<LoadingPanel Url="~/App_Themes/Office2010Blue/GridView/Loading.gif">
</LoadingPanel>
</Images>
<ClientSideEvents ContextMenu="grid_ShowContextMenu" />
<ClientSideEvents BeginCallback="function(s, e) { OnBeginCallback(s,e); }" />
<ClientSideEvents EndCallback="function(s, e) { OnEndCallback(s,e); }" />
<StylesEditors>
<ProgressBar Height="25px">
</ProgressBar>
</StylesEditors>
</dxwgv:ASPxGridView>
<asp:SqlDataSource ID="GridSource" runat="server"></asp:SqlDataSource>
And here's the event handler for BeforePerformDataSelect:
private bool _DataBindingCompleted = false;
protected void grid_BeforePerformDataSelect(object sender, EventArgs e)
{
if (_DataBindCompleted) Grid_PerformDataSelect(sender, e);
}
protected override void Grid_PerformDataSelect(bool ClearSelection)
{
if (ClearSelection) this.grid.Selection.UnselectAll();
GridSource.ProviderName = System.Configuration.ConfigurationManager.ConnectionStrings["mysql"].ProviderName;
GridSource.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["mysql"].ConnectionString;
SetupSearch();
//if (this.FilterContext.Count > 0 || !string.IsNullOrEmpty(grid.FilterExpression))
//{
string FilterSQL = DevExpressUtils.GetMySQLFilterExpression(grid);
string OrderBySQL = DevExpressUtils.GetSQLOrderByExpression(grid, "OrderID");
//FilterSQL = FilterSQL.Replace("[PatientID]", "vwPatients."+ Patient.PRIMARYKEY);
if (Utils.GetAppSettingBool("MYSQL"))
{
GridSource.SelectCommand = this.MP.CurrentUser.GetEOSHeaderSQL(this.FilterContext, FilterSQL, "");
}
else
{
GridSource.SelectCommand = "";
}
}
protected override void Grid_PerformDataSelect(object sender, EventArgs e)
{
bool IsFromParent = this.ClientID.StartsWith(this.MP.GridCallback);
if (grid.Visible && (!this.Page.IsCallback ||
((this.MP.GridCallback == this.grid.ClientID && (this.MP.GridCallbackCommand != "SHOWDETAILROW" || this.IsDetailGrid))
|| (this.MP.GridCallbackCommand == "SHOWDETAILROW" && IsFromParent)
)
)
)
{
Grid_PerformDataSelect(false);
}
}
protected void grid_AfterPerformCallback(object sender, ASPxGridViewAfterPerformCallbackEventArgs e)
{
_DataBindCompleted = true;
((DevExpress.Web.ASPxGridView.ASPxGridView)sender).DataBind();
}
protected void Page_Init(object sender, EventArgs e)
{
grid.DataSource = GridSource;
}
protected new void Page_Load(object sender, EventArgs e)
{
this.grid.ClientInstanceName = this.grid.ClientID;
if (!this.IsPostBack)
{
_DataBindCompleted = true;
grid.DataBind();
}
}