Ask the Expert

Implementing a ComboBox control in ASP.NET

The DropDownList control does not provide editability, i.e. does not act as a ComboBox. The only thing you can do with DropDownList is to pick up an item from a list, but you cannot type in your own text. Is this correct? If yes, could you please advise how to implement a kind of a ComboBox control in ASP.NET? Thank you.
Platform: Win2000
Implementing the ComboBox in ASP.NET would consist of: a composite custom control, containing a textbox for the editable region, an image for the "faked" dropdown, next to the textbox, and a <div> containing all items. With JavaScript, you'd have to react to the click on the image, and show/hide the div (i.e. set its "display:block" or "display:none"). You'd have to take care of positioning too. Alternatively, you could try having both a textbox and a dropdown list with absolute positioning, overlapping each other. You can make the textbox narrower than the dropdown so the arrow appears (the dropdown should have it's Z-order less than the textbox'). Then, through JavaScript, when the user clicks on an item in the dropdown, you set the textbox value accordingly.

This was first published in June 2004

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: