How Do I: Use the ASP.NET AJAX AutoComplete Control

The AutoComplete extender control from the ASP.NET AJAX Control Toolkit provides real-time suggestions to the user as he or she types in a text box on the Web page, where the list of suggestions is obtained by an asynchronous call to a Web service on the server.

Presented by Joe Stagner

Duration: 7 minutes, 7 seconds

Date: 20 March 2007

Watch the video   |   Download the video   |   Get VB code  or  C# code

Video downloads: WMV | Zune | iPod | PSP | MPEG-4 | 3GP

Audio downloads: AAC | WMA | MPEG-4 | MPEG-3 | MPEG-2

Comments : 4

Leave a Comment

jorge08 : On May 11, 2008 8:05 PM said:

Hi Joe, maybe you have a sample about this control using a database?

warrenvt : On June 02, 2008 1:50 PM said:

Hi Joe,

  I have an external web service that has been created for me to allow me access to a db. How can I use the AJAX to connect to this web service?

Gabriel82 : On June 07, 2008 8:44 AM said:

Jorge08 this is a small example with Access Database:

If (count = 0) Then

           count = 10

       End If

       Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("App_Data/ExpImpdb.mdb") & ";"

       Dim adp As New System.Data.OleDb.OleDbDataAdapter("select * from cars WHERE RecMerk Like '" & prefixText & "%' ", strConn)

       Dim dt As New System.Data.DataTable

       adp.Fill(dt)

       Dim items As New List(Of String)

       For i As Integer = 0 To dt.Rows.Count

           Dim datafile

           datafile = UCase(dt.Rows(i).Item("RecMerk"))

           i += 1

           items.Add(datafile)

       Next

       Return items.ToArray()

Sabeltann : On June 20, 2008 7:38 AM said:

Thanks Joe! I've wanted to try making an AJAX control like this for a while, but always thought it'd be more complex - you made it look easy.

From a beginner's viewpoint it wasn't obvious to me that when creating the webmethod, you can change the webmethod name as you like but the parameter names _must_ be prefixText and count (but maybe that's me being dumb)

It seems pretty easy to hook this up to a database using LINQ. If it's of any help, here's my code to query product names in Northwind, (assumes you've already made the linq to northwind class)

[WebMethod]

public string[] GetCompletionList(string prefixText, int count)

{

 // OBS! In real world, initialize this someplace else

 NorthwindDataContext Db = new NorthwindDataContext();

 var matches = from p in Db.Products

 where p.ProductName.StartsWith(prefixText)

 select p.ProductName;

 return matches.ToArray<string>();

}

Leave a Comment

You must be logged in to leave a comment. Click here to log in.