Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

jquery autocomplete or ASP AutoCompleteExtender

Posted on 2013-06-29
2
Medium Priority
?
1,176 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 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.    
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 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 + "%")
 else
    Add company name parameter, for example your code should look like:  cmd.Parameters.AddWithValue("@CompanyName", prefixText + "%")
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

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

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
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…
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…
Suggested Courses
Course of the Month15 days, 19 hours left to enroll

580 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