views:

207

answers:

2

I am trying to implement a search bar in Asp.Net where the results change with every key press. I want the search bar to contain a drop down list of available results pertaining to what they have typed in thus far.

So if you were searching for states, and you typed M, it would list all states starting with M, but if you add an i to that...it would truncate the results to to only those that start with Mi.

Right now I have just a textbox that calls a method when the text changes. The problem is you only see the results if you reload the page. I could reload the page in the method but that seems wrong.

Is there an easier way to do this?

+1  A: 

Try the AjaxControl Toolkit's AutoComplete..

http://www.asp.net/AJAX/AjaxControlToolkit/Samples/AutoComplete/AutoComplete.aspx

madcolor
That is exactly what I want to do...although it says that it contacts a webservice. I just want it to refer to users I have listed in an sql database.
Since what you're really trying to do is an Ajax call, I would suggest you write a simple webservice to deliver the data. Otherwise, you'll probably be stuck doing a postback anyhow.
madcolor
@sweetcoder: It might work with a WebMethod if you don't want to add a full web service to your application.
Pawel Krakowiak
Indeed.. Pawal is correct, you should be able to write a webmethod to deliver the data.
madcolor
what exactly is a web method? example???
A: 

I would use jQuery along with its $.autocomplete method as it's much more customizable.

More info and demo here.

alexn