how to remove case sensitivity in ASP.Net Query Extender data field search?

871 Views Asked by At

I applied a query extender to my text box for three fields. Its Working but it is case sensitive. e.g. if a username field is having a name "AWAIS" and i search for "awais" , it does not search and vice virsa. How can i remove sensitivity ?

My Code is

    <td>
                <asp:LinqDataSource ID="LinqDataSource1" runat="server" ContextTypeName="BookStore.Bussines.Entities.BookStoreEntities"
                    OnSelecting="LinqDataSource1_Selecting">
                </asp:LinqDataSource>
                <asp:QueryExtender ID="qeSearch" runat="server" TargetControlID="LinqDataSource1">
                    <asp:SearchExpression DataFields="DISTRIBUTOR_NAME,DISTRIBUTOR_CODE,DISTRIBUTOR_URL" SearchType="Contains">
                        <asp:ControlParameter ControlID="txtSearchDistributor" />
                    </asp:SearchExpression>
                </asp:QueryExtender>
            </td>
3

There are 3 best solutions below

0
Rick S On BEST ANSWER

According to the documentation:

Case sensitivity in the search expression depends on the LINQ provider that you specify in the QueryExtender control.

If the LINQ provider that you use in the QueryExtender control supports case sensitivity, you can use the ComparisonType property to enable or ignore case sensitivity.

Another Possibility - Database Collation

Perhaps your database is set up to be case sensitive. Some links if you're using SQL Server.

SQL Server Collation Description

Description of Collations

0
Jamie Keeling On

If you look at the documentation on MSDN for this control you would see how case sensitivity is handled:

Case sensitivity in the search expression depends on the LINQ provider that you specify in the QueryExtender control.

0
malkam On

Try this:

Set SearchExpression.ComparisonType to StringComparison.OrdinalIgnoreCase

<asp:SearchExpression DataFields="DISTRIBUTOR_NAME,DISTRIBUTOR_CODE,DISTRIBUTOR_URL" SearchType="Contains" ComparisonType=StringComparison.OrdinalIgnoreCase>
                        <asp:ControlParameter ControlID="txtSearchDistributor" />
                    </asp:SearchExpression>

https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.expressions.searchexpression.comparisontype%28v=vs.110%29.aspx

https://msdn.microsoft.com/en-us/library/system.stringcomparison%28v=vs.110%29.aspx