Solved

jquery autocomplete or ASP AutoCompleteExtender

Posted on 2013-06-29
2
1,118 Views
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:
http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/AutoComplete/AutoComplete.aspx
 
or

Using the jquery UI Autocomplete located here:
http://jqueryui.com/autocomplete/


For discussion sake, I will talk about this example:
http://www.codeproject.com/Articles/201099/AutoComplete-With-DataBase-and-AjaxControlToolkit

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?

OR

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.
0
Comment
Question by:maqskywalker
2 Comments
 
LVL 52

Assisted Solution

by:Scott Fell, EE MVE
Scott Fell,  EE MVE earned 250 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.    
term=request("term")
arrTerm=split(term," ")
firstname=arrTerm(0)
lastname=arrTerm(1) 

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.
0
 
LVL 35

Accepted Solution

by:
Miguel Oz earned 250 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 + "%")
 else
    Add company name parameter, for example your code should look like:  cmd.Parameters.AddWithValue("@CompanyName", prefixText + "%")
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now