Click to See Complete Forum and Search --> : Ability to Type in a WebControl DropDownList [ASP C# 2003]


Shaitan00
June 7th, 2007, 03:08 PM
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,

mcmcom
June 7th, 2007, 03:29 PM
you can simply create a text box and a button beside the drop down list and write code to add it to the drop down list.

example
you have dropdownlist named ddl1.
you have textbox named txtNewEntry
you have a button named btnAddNewEntry

1. User enters text in txtNewentry.
2. On Press of btnAddNewEntry you do something like

string tmpString = this.txtNewEntry.Text.ToString();
//make sure somethings there
if(tmpString.Length > 0){
dd1.Items.Add(tmpString);
}


thats a very simplified example, you may need to add a value to it as well (if the value differs from the displayed text) you probably want to throw a Validator on there too to make sure the entered value is in a format it should be in.

hth,
mcm

Shaitan00
June 7th, 2007, 03:43 PM
Thats a good idea but I was hoping to instead use the same layout (adding a text box and button won't fit with the current spacing of the DropDownList used - is there no way to allow the user to type directly in the web control?

mcmcom
June 7th, 2007, 03:47 PM
i think there is a 3rd party control that allows this. Alternatively you can place the textbox and button right above the drop down list. Or you can use panels to hide / show the dropdown list or a text box.

heres a editable dropdownlist control example :
http://www.codeproject.com/aspnet/EditableDropdown.asp

if you google "editable dropdown list" you should be able to find some controls. Some will probably be pay and some may be free!

Just remember that working like this on the web will cause postbacks in order to refresh the drop down list, as well if you want it re-used (ie the new additions to stick around forever) your going to have to write the list contents to a db or xml file because once the user leaves the page whatever they added (if its just in memory) will be gone.

hth,
mcm