Adding a "None Selected" option to a DropDownList control that uses Databinding

N

Nathan Sokalski

I have several DropDownList controls on my page that use databinding.
However, I want to give users the option of selecting a choice such as "None
Selected" or something else that shows they did not make a selection.
However, if I attempt to add a ListItem to the Items collection when
databinding is used it is removed and replaced by the item in the
databinding source. Is there any simple way to add an extra ListItem, or do
I have to build the collection using separate code? Thanks.
 
G

Guest

You can also use:
DropDownList.Items.Insert(0, new ListItem("-99", "None Selected"))

This allows you to control also Value of new item also with Text. It might
get handy when validating user input in postback.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top