There are several thing I have noticed in your code:
- First of all, autocomplete is not for returning too many rows, since that has makes no sense. It is meant to be used by people, so a maximum of 15-20 elements is enough. While the user is typing, the list will refine content.
- You are currently filling up the autocomplete list in the html code (from code behind, but that's the same in this situation), so you have every element in the html which makes it static in some form. You should use the dynamic version, with an ajax callback to a ScriptService. Check this:
http://jquery-with-asp.net/2011/07/jquery-ui-autocomplete-with-asp-net/[
^]
- Use the text portion entered by the user (the parameter you get in the scriptservice method) to filter the returned list. All the conditions you added from code to get records with proper values - you can put in the select statement. You should put them there. And you should put a limitation to the fetched records by adding a
TOP clause[
^].
The query would look like this:
SELECT TOP 20 fieldname FROM table WHERE fieldname IS NOT NULL AND fieldname NOT IN ('value1','value2','value3','value4') AND الاسم LIKE @filter
(And do't forget to add wildcards to the @filter when passing the parameter value)