Solved

retrieve data from database using jquery autocomplete

Posted on 2013-01-18
6
417 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
  • 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
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!

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Code works but how can I download the file? 20 47
AWS CLI issues with Tags 3 32
Spacing between controls 4 17
Problem to page 4 29
Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
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…
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…

744 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

13 Experts available now in Live!

Get 1:1 Help Now