Multiple possible FilterExpression's on SqlDataSource issue
I have an SqlDataSource in a page, which will display different results depending on 1 or 2 query strings, and/or a filter textbox.
Here is my SqlDataSource and filters:
<asp:SqlDataSource ID="sdsAudits" runat="server"
ConnectionString="<%$ ConnectionStrings:constring %>"
SelectCommand="SELECT * FROM [Audit]" FilterExpre开发者_StackOverflow社区ssion="source = {0} AND customer = {1} AND (itemID like '%{2}%' OR parentID like '%{2}%')">
<FilterParameters>
<asp:QueryStringParameter Name="source" QueryStringField="source" />
<asp:QueryStringParameter Name="customer" QueryStringField="customer" />
<asp:ControlParameter Name="txtFilter" ControlID="txtFilter" PropertyName="Text" />
</FilterParameters>
But for some reason, the filtering for any of the 3 possible filters don't work. I tried taking out the 2 query string filters, and leaving just the textbox filter, and it worked fine then - so I'm guessing my filter expression is wrong?
Any ideas guys? Remember all 3 filters could be 'active' at once, if they have the 2 query strings and have typed into the textbox, or they could be none at all, or of course anything in between.
Filter is intended to work in DataSet mode - data is retrieved into memory, and then filtered. Not very efficient - much better to use parameters in the select command itself, like so:
<asp:SqlDataSource ID="sdsAudits" runat="server"
ConnectionString="<%$ ConnectionStrings:constring %>"
SelectCommand="SELECT * FROM [Audit] where source = @source AND customer = @customer AND (itemID like '%' + @txtFilter + '%' OR parentID like '%'+@txtFilter+'%')">
<SelectParameters>
<asp:QueryStringParameter Name="source" QueryStringField="source" />
<asp:QueryStringParameter Name="customer" QueryStringField="customer" />
<asp:ControlParameter Name="txtFilter" ControlID="txtFilter" PropertyName="Text" />
</SelectParameters>
</asp:SqlDataSource>
or just add
DataSourceMode="DataSet"
to your SqlDataSource tag
精彩评论