Solved

retrieve data from database using jquery autocomplete

Posted on 2013-01-18
6
421 Views
Last Modified: 2013-01-22
Hello Experts,

I would like to have values from my database get autocompleted as I type in a TextBox control. I'm having trouble finding good examples of this online. Could really use some help.
0
Comment
Question by:asp_net2
[X]
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
  • 3
  • 2
6 Comments
 
LVL 20

Expert Comment

by:Russ Suter
ID: 38794621
If you're talking about a relatively small number of values then you should pull them into memory ahead of time. If you have a lot of records then you may be looking at a large number of queries in a short time which isn't an especially good idea.

Can you give me some idea of how many records you're looking at retrieving? There are ways to do this but the question is if it's a good idea or not.
0
 
LVL 4

Author Comment

by:asp_net2
ID: 38794650
I would say it would be around 150 - 300 records.
0
 
LVL 20

Expert Comment

by:Russ Suter
ID: 38794792
For a list that small I'd just query the database once at page load and store the values in memory.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Author Comment

by:asp_net2
ID: 38794863
Ok, can you help with that. That part I already understand.
0
 
LVL 10

Accepted Solution

by:
Monica P earned 500 total points
ID: 38799987
Hi

This is a good artice in found on net..Let u try and check

http://www.aspdotnet-suresh.com/2012/03/jquery-ui-autocomplete-textbox-with.html
0
 
LVL 4

Author Comment

by:asp_net2
ID: 38801289
@AkilaPalanimuthu,

Thank you for the link. That worked out great. I have just a few small questions to ask though before closing this post.

1.) How can I use a Stored Procedure instead of an SQL Statement as below?

    [WebMethod]
    public static List<string> GetAutoCompleteData(string username)
    {
        List<string> result = new List<string>();

        using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["CMDB"].ConnectionString))
        {
            using (SqlCommand cmd = new SqlCommand("select DISTINCT product_name from ProductNumbers where product_name LIKE '%'+@SearchText+'%'", conn))
            {
                conn.Open();
                cmd.Parameters.AddWithValue("@SearchText", username);

                SqlDataReader dr = cmd.ExecuteReader();

                while (dr.Read())
                {
                    result.Add(dr["product_name"].ToString());
                }

                return result;
            }
        }
    }

Open in new window


2.) Is there a way to have another value get populated based on the selected value from the AutoComplete list? So for example. I have a textbox called Product Number that is getting retrieved using autocomplete. Once a user selects a value from autocomplete I then need to populate the value related to the selected autocomplete value to be returned to a label control. The values in the database are related I jsut don't know how to return the other value based on the selected value from the autocomplete.

I would be MORE than willing to create another ticket if you think you can assist me with that.
0

Featured Post

Report: Liquid Web beats Amazon, Rackspace & More

A study by performance analyst firm Cloud Spectator finds that Liquid Web beats rivals Amazon, Rackspace and DigitalOcean when it comes to website and cloud application performance.

Question has a verified solution.

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

Suggested Solutions

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

739 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