Ability to Type in a WebControl DropDownList [ASP C# 2003]

Shaitan00

Junior Contributor
Joined
Aug 11, 2003
Messages
358
Location
Hell
Currently I have a webform that has DropDownLists populated with specific choices the user can select - problem is he is limited to those choices and cannot enter his own selection (as if he was typing if a free field). I want to provide him the ability to either use the dropdownlist to select one of the predefined options OR type in his own choices (in the same DropDownList) to be used...

I knows Forms don't work the same (that is what I am used to) where you can specify what kind of dropdown it is (and one of them allow you to also type in the listbox) - is there such a property or option for the Web Control DropDownList? Is there a way to achieve my goal without breaking my current web application?

Any help, hints, or ideas would be greatly appreciated.
Thanks,
 
Maybe using Javascript, or just use 2 controls

ASP.Net server controls are limited to what is possible using HTML/XHTML markup. The DropDownList control renders as a <select> element which is a simple drop down list - this is why the control is not called ComboBox, as it does not support ComboBox behaviour.

To provide ComboBox-style behaviour, you would have to have a TextBox (<input> element) directly on top of a DropDownList (<select> element) with just the button portion of the dropdown showing, then use Javascript to cause the appropriate behaviour when either the dropdown is clicked, an item is selected, or the text in the textbox is changed. It sounds possible, but might be more trouble than it is really worth.

An alternative is to provide both a DropDownList and a TextBox seperately on the page, and use server-side code to decide which value to use - for example, if the textbox value is changed, use that, otherwise use the dropdown value. You could also add a pair of RadioButtons to allow the user to explicitly state whether they are selecting a value from the dropdown or entering their own value, and with a bit of Javascript you could make the radios toggle depending on which control has focus.

Good luck :cool:
 
Back
Top