Solved

jquery autocomplete or ASP AutoCompleteExtender

Posted on 2013-06-29
2
1,134 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 36

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Suggested Solutions

How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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)
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…

733 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