Use QueryExtender to Search for Term across Multiple DataFields?
I have a textbox with button wired up to a queryextender. My goal is that someone might enter into the textbox a name (e.g. "Dave Mackey") and receive back all relevant results. The problem is that this information is spread across two columns开发者_高级运维 in the underlying database (e.g. FIRST_NAME, LAST_NAME). My code looks like this:
<asp:QueryExtender ID="QueryExtender1" runat="server" TargetControlID="EntityDataSource1" >
<asp:SearchExpression DataFields="first_name,last_name" SearchType="Contains">
<asp:ControlParameter ControlID="txtFilterText" />
</asp:SearchExpression>
</asp:QueryExtender>
If I enter "Mackey" it returns results, but "Dave Mackey" returns no results, I'm assuming b/c it is looking for the entire value in one first (either, but not both together), whereas I want it to return any rows where it finds the entirety even if it is spread across multiple DataFields. Any ideas?
You are correct in your assumption.
QueryExtender's SearchExpression performs the search using the entire txtFilterText in each field in the DataFields enumeration.
What about using Dynamic LINQ and specifying a custom query in the EntityDataSoure OnSelecting event?
精彩评论