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

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 429
  • Last Modified:

retrieve data from database using jquery autocomplete

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
asp_net2
Asked:
asp_net2
  • 3
  • 2
1 Solution
 
Russ SuterCommented:
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
 
asp_net2Author Commented:
I would say it would be around 150 - 300 records.
0
 
Russ SuterCommented:
For a list that small I'd just query the database once at page load and store the values in memory.
0
Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

 
asp_net2Author Commented:
Ok, can you help with that. That part I already understand.
0
 
Monica PSoftware DeveloperCommented:
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
 
asp_net2Author Commented:
@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

Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now