Brian
asked on
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.
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.
ASKER
I would say it would be around 150 - 300 records.
For a list that small I'd just query the database once at page load and store the values in memory.
ASKER
Ok, can you help with that. That part I already understand.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@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?
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.
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;
}
}
}
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.
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.