Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Text box with drop down suggestions

I currently have a databound dropdown list on my ASP.Net C# 2.0 website that has around 400 items in it. I want to replace it with something similar like the textbox in google search where you enter letter and only the entries starting with those letters pop up

what is a good way of implementing it? Are there controls that already exists that anybody can suggest?

like image 792
randomThought Avatar asked Sep 30 '09 21:09

randomThought


People also ask

How do you AutoComplete when typing a drop down list?

Press Alt + Q keys simultaneously to close the Microsoft Visual Basic Applications window. From now on, when click on a drop down list cell, the drop down list will prompt automatically. You can start to type in the letter to make the corresponding item complete automatically in selected cell.

How do you show the suggestion list in the input field?

Approach: Create a div with the class as a container. Inside of this div, create another div with a class as a text-container that will contain the <input> tag & <datalist> tag. Declare the list attribute as programmingLanguages inside the <input> tag.

How do I activate a TextBox if I select an option in drop down box?

When an item (option) is selected in DropDownList (HTML SELECT), the EnableDisableTextBox JavaScript function is executed. Inside this function, based on whether the Other option (item) is selected, the TextBox will be enabled else disabled. The HTML Markup consists of a DropDownList (HTML SELECT) and a TextBox.


4 Answers

One way to do this using HTML5 (for small datasets of course) is datalist:

<input list="users" name="users">
  <datalist id="users">
    <option value="Alice">
    <option value="Bob">
    <option value="Chuck">
    <option value="Chris">
    <option value="Duke">
    <option value="Emily">
  </datalist>

For larger datasets AJAX is a better way to go.

like image 190
jayantS Avatar answered Sep 30 '22 18:09

jayantS


Take a look at http://docs.jquery.com/Plugins/Autocomplete

Also here is a tutorial for use with ASP.Net

like image 45
AdamW Avatar answered Sep 30 '22 19:09

AdamW


check complete.ly too

http://complete-ly.appspot.com/

it has no dependencies and weights very little.

like image 25
Zo72 Avatar answered Sep 30 '22 19:09

Zo72


If these are known enrties, you can use JQuery, and on the OnUpdate event:

  1. if it's a long list, make Ajax Request to your webserver, retrieve the best option
  2. if it's a short list, you can load all the options to the page, and offer the optional texts without making a server request.

Checkout the JQuery library for implementations on how to display the suggestion.

like image 29
Amirshk Avatar answered Sep 30 '22 19:09

Amirshk