I need my textbox to autocomplete when the user types. The value should come from the database. I am using the textchange property of the textbox.
protected void autocomplete(object sender, EventArgs e)
{
string query = "Select area,codes from tbl_pincode";
SqlConnection conn = new SqlConnection("Data Source=win2008-2;Initial Catalog=h1tm11;User ID=sa;Password=#1cub3123*;Persist Security Info=True;");
SqlCommand com = new SqlCommand(query, conn);
conn.Open();
SqlDataReader dr = com.ExecuteReader();
while (dr.Read())
{
zipcode.Text = dr.GetValue(0).ToString();
}
conn.Close();
}
But i m not getting the desired result. Any ideas how to go about it?
Add web form right click on project add new item and choose web form. Add script and styles cdn link in head section. Design HTML by grad and drop textbox control in web form. Complete html code of web form.
Append displays first value of the suggestion appended or selected in the TextBox, other values can be navigated using arrow keys. SuggestAppend displays suggested values as dropdown and first value appended in the TextBox. AutoCompleteSource property sets the source for auto complete data.
Have you looked at using the jquery ui autocomplete component? You can hook this up to a remote datasource
http://jqueryui.com/demos/autocomplete/
You can use jQuery UI for autocomplete: http://www.dotnetcurry.com/ShowArticle.aspx?ID=515
Another option for ASP.NET autocomplete is AjaxControlToolkit: http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/AutoComplete/AutoComplete.aspx
EDIT:
If you choose to use the JQueryUI autocomplete, I'd start from the remote JSONP example.
You can point the url
property of the ajax
call inside the autocomplete's source
function to a WebMethod in your page. This will receive an object containing the filter (data
in the example) and return the required values from your database in JSON format (e.g. see this example)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With