Setting asp:DropDownList Control Value to nothing

  • Thread starter Thread starter Greg
  • Start date Start date
G

Greg

I have a page that displays a DropDownList control that allows a Manager Name
to be selected from a listing of Managers for a User. So, on my main
user.aspx page, I include a DropDownList control for ManagerID. This dropdown
list provides three options to choose for managers. Right now, most users do
not have a Manager selected yet, thus the User's ManagerID value would be
null. How can I make the DropDownList control show nothing selected when the
data source value is null? I want nothing selected when no selection has been
made.
 
Greg said:
I have a page that displays a DropDownList control that allows a Manager Name
to be selected from a listing of Managers for a User. So, on my main
user.aspx page, I include a DropDownList control for ManagerID. This dropdown
list provides three options to choose for managers. Right now, most users do
not have a Manager selected yet, thus the User's ManagerID value would be
null. How can I make the DropDownList control show nothing selected when the
data source value is null? I want nothing selected when no selection has been
made.

A DropDownList always has one item that is selected.

You just have to add a "none selected" item and make that selected when
the value is null.

If the data source is a database, you would get a DbNull value. That
converts into an empty string, so if you set the value of the "none
selected" item to an empty string, it should get selected for null values.
 

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

Back
Top