Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


jquery autocomplete or ASP AutoCompleteExtender

Posted on 2013-06-29
Medium Priority
Last Modified: 2013-07-02
Hi experts,

I'm want to create an autocomplete textbox using either one of these 2 tools.

Using the ASP.NET AJAX Control Toolkit AutoCompleteExtender such as this one:

Using the jquery UI Autocomplete located here:

For discussion sake, I will talk about this example:

If you look at this example the autocomplete uses this SQL Server query:

select * from tblCustomer Where CompanyName like @myParameter

So when you type a letter or letters in the autocomplete textbox, it looks up similar spelled items from the CompanyName column  in the table called tblCustomer.

I already did this example and it worked great but my question is this.

Is it possible do something like the following:

Suppose in my tblCustomer table I had another column called CompanyID of integer datatype. So the table might look something like this:

CompanyID  CompanyName
10020            Acme Inc.
11234            Panda Express
14553            Hasbro inc.
14559            Pepsi Cola Company
14567            Mattell Inc.

Is it possible to set it up that in my autocomplete I can either type in a CompanyID or CompanyName when it does the autocomplete suggestion list.

So for example  if I typed "14" in the autocomplete textbox then these  items would show up, because it looked them up from CompanyID column:

14553            Hasbro inc.
14559            Pepsi Cola Company
14567            Mattell Inc.

Or if instead I typed "P" in the autocomplete textbox then these  items would show up, because it looked them up from CompanyName column:

11234            Panda Express
14559            Pepsi Cola Company

Do you know how I might modify the example mentioned above to do something like this?


Do you know a book or a website link tutorial to a similar example on the internet either using the jQuery UI Autocomplete or the ASP AJAX Toolkit AutoCompleteExtender and SQL Server?

To summarize, I want to set up autocomplete to allow the user to enter items from 2 different columns.

Thanks for any references or info you can give me.
Question by:maqskywalker
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 54

Assisted Solution

by:Scott Fell, EE MVE
Scott Fell,  EE MVE earned 1000 total points
ID: 39287645
I do this in classic asp with jquery and you should be able to convert.  The way this works is you have 2 pages.  page1 is where the autocomplete form is and page2 is a page to accept a get request and based on the get request, display data in json format.  As you type in page1, an ajax request goes to page2 that shows up as the autocomplete back on page1.

The get request is just one parameter.  You end up with page2 creating a recordset based on the querystring, ?term=sometthing.     If you have multiple columns to check, I create an array using a space as the delimiter.  If somebody types in the autocomplete box, "firstname lastname" or more likely, "fir las" it comes through as ?term=fir%20las.    In vbs I convert this to an array.    
arrTerm=split(term," ")

Open in new window

Now the trick is to build in the logic to determine how you want to determine if you are searching multiple columns or not.  This will depend on the columns you are searching.
LVL 36

Accepted Solution

Miguel Oz earned 1000 total points
ID: 39288917
Basically you need to idetify whether prefixText  is an integer or alphanumeric string:

Your logic should look like: (It replaces this line:  cmd.Parameters.AddWithValue("@myParameter", "%" + prefixText + "%") in your codeproject link sample code)

if prefixText  is an integer then (For example you can use TryParse method)
    Add company Id parameter, for example your code should look like:  cmd.Parameters.AddWithValue("@CompanyID", prefixText + "%")
    Add company name parameter, for example your code should look like:  cmd.Parameters.AddWithValue("@CompanyName", prefixText + "%")

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer…
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question