开发者

Searchfield with autocomplete ASP.NET and Database

Searchfield with autocomplete

I would like to make a searchfield with autocomplete, so when you write like 2 or 3 letters it will show a dropdownlist with results that match a column from a table in the database开发者_JAVA百科.

I have been reading all over the internet, and i have found out that it can be done with jQuery and AJAX Control Toolkit. But i don't know how to make it compare the search textbox and the database and show results that match?

UPDATE:

I have been trying to make it work with Autocomplete extender from Ajax control toolkit, but i don't know how to make the Webservice with SQL.

UPDATE2

Can't get the webservice to work, so have been looking at jQuery UI, which can do autocomplete but don't know how to get that working with the database either.. :p

UPDATE3

I'm still stuck on this, so if anyone who knows how to make a datasource(webservice) that works with either Autocomplete extender or jQuery UI, please help me.

I want the autocomplete to show: SELECT * FROM TABEL WHERE Title LIKE + '%' @Search + '%' And its an MSSQL Database


You can use Asp.net Ajax control toolkit.

http://www.asp.net/ajax/ajaxcontroltoolkit/Samples/AutoComplete/AutoComplete.aspx

The database can be searched as shown below.

select * from tbl_Country where countryName like '%xxx%'

You can call sql statement from a Service method. Service method can be a web service.

<ajaxToolkit:AutoCompleteExtender 
    runat="server" 
    ID="autoComplete1" 
    TargetControlID="myTextBox"
    ServiceMethod="GetCompletionList"
    ServicePath="AutoComplete.asmx"
</ajaxToolkit:AutoCompleteExtender>

Create an asmx web service in your web application named AutoComplete.asmx. Then create a web method GetCompletionList. Inside this method you can include System.Data.SqlClient and fire the query to the database.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜