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.
 
Back
Top