views:

35

answers:

2

Hi,

I want to provide an autocomplete option for a text in my web applciation . I have the master data in the SQL server database table. I beowsed in google and found how to use autocomplte. all the examples use web service to do this. I cannot create a web service to impltement this. Is it possible to implement autocomplete by looking up values from database in code behind ? If so any one can provide any sample links for reference ?

Thanks in advance,

Jebli

+3  A: 

It depends on the volume of data. There are 2 options:

  • send it to the client pre-emptively (perhaps as json or html) in the page source
  • let the client query it based on their input

The second is common if the data-volume is non-trivial, as you can query when (for example) they've entered 3 characters; very useful for names and other long lists.

Re the web-service; this doesn't have to be a full/complex web-service; just a simple route or ashx (for example) that returns the filtered data.

The jquery autocomplete plugin supports both scenarios, although this is now partly obsoleted by jquery ui plugin.

Is it possible to implement autocomplete by looking up values from database in code behind

Well, that is at the server - so you're essentially talking about the same "web service" that you say you can't do... I also think you should separate out the 2 functions (create page vs provide auto-complete results) into separate files (/pages/whatever).

Marc Gravell
I have only one text box where i have to implement sutocomplte for the whole applciation. Should i create a new web service for this functionality . it would be better if there is any alternative way . thanks for the reply.
Jebli
@Jebli - I think you've putting too much emphasis on "web service"; it is just a url that returns some data. An ashx will do the job. Aspx *can* do it, but it is harder to get the formatting right. An MVC route is easiest of all, obviously.
Marc Gravell
ok thanks for the comments. Your suggestions was very useful to me. thanks.
Jebli
+1  A: 

A simple way would be to make a new aspx page that takes the autocomplete query as querystring parameters, looks up the result in a database and returns the response as XML og JSON.

Per-Frode Pedersen