DropDownList Question

W

Will Lastname

My application has a series of dropdownlists with AutoPostBack set to
True and IndexChanged handlers as well. All of the dropdownlists are
bound and dynamically populated.

Is there a way to manually add an entry to a dropdownlist that is
bound? The reason I ask is because if the first item is the one the
user wants to select it is not able to postback since it is already
selected.
 
G

Guest

Hi Will,

You could just add a new item into the underlying data source.

For example, if you are using a datatable as the datasource, add a new row
to it with the topmost value to display, and then bind to the drop down.

You could also set up client side scripts so that a client-side validation
would ensure the user has made a valid selection.

Does this help?
 
D

darrel

Is there a way to manually add an entry to a dropdownlist that is

Yes.

DropDownListNavigation.DataBind()
DropDownListNavigation.Items.Insert(0, New ListItem("Pick An Option",
"null"))

-Darrel
 
W

Will Lastname

Thanks to both of you. I am sorry to say that I am still getting an
error stating that I can't modify this list when a datasource property
is set. Thanks anyway!
 
D

darrel

Thanks to both of you. I am sorry to say that I am still getting an
error stating that I can't modify this list when a datasource property
is set. Thanks anyway!

Did you use the code example I showed you? That seems to work fine in my
application. What is the exact error you get?

-Darrel
 

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

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top