DropDownList w/o default

  • Thread starter Thread starter Michael Groeger
  • Start date Start date
M

Michael Groeger

Hi,

is it possible to leave a DropDownList's selection empty? Our application
requires for some ddl's that they are kept blank w/o an initial value so
that we can add a RequiredFieldValidator to them.

Regards,
Michael
 
Generally this is done by adding an adtional entry with a text such as
"(Please select a value)"

Patrice
 
Some people, including myself, prefer doing it on the bound datatable.

Eliyahu
 
Patrice, Eliyahu,

thanks for your reply. I understand that I can solve it that way, but this
both would mean that "(Please select a value)" is at least a valid value for
the DropDownList. How would I get it work together with Field Validators (I
must admit that I am still new to ASP.NET and don't know much about working
with them)? What value should I define for the ListItem which states
"(Please select a value)"?

Eliyahu, mixing database design with application design, seems for me not to
be a good start. It is much easier to do so, but it would mean that values
which are only required to fix application issues are treated as valid
values in the database.

When trying to do the same for Windows Forms applications I do have
ComboBoxes (which seems to me the pendant to DropDownLists) where as default
no item is selected. This is much easier for us to work with.

Regards,
Michael
 
thanks for your reply. I understand that I can solve it that way, but this
both would mean that "(Please select a value)" is at least a valid value for
the DropDownList. How would I get it work together with Field Validators (I
must admit that I am still new to ASP.NET and don't know much about working
with them)? What value should I define for the ListItem which states
"(Please select a value)"?
Who forces you to use validators? I am not so new to ASP.NET already, but I
never used them anyway.
I would recommend using text "(Please select a value)" only if a value must
be selected and there is no default one. If there is a default, you should
set it selected straight away. If the selection is optional, you should make
original text empty.
You can use an empty string as a value, or whatever else that will tell the
application that no selection has been made.
Eliyahu, mixing database design with application design, seems for me not to
be a good start. It is much easier to do so, but it would mean that values
which are only required to fix application issues are treated as valid
values in the database.
No, I did not mean the table in the database. I mean the DataTable in the
Dataset the list is bound to. Or any other dotnet datasource for this
matter. And as far as database design is concern you are 100% right.
When trying to do the same for Windows Forms applications I do have
ComboBoxes (which seems to me the pendant to DropDownLists) where as default
no item is selected. This is much easier for us to work with.
Welcome to the web design world!
 
You can use a required field validator for this. Just set the initial
value property to whatever item is initially selected ("Select an Item"
or ""). This will force the user to make a selection other than the
initial value.
 
Eliyahu,

thanks for you follow-up.
Who forces you to use validators? I am not so new to ASP.NET already, but I
never used them anyway.

Well, it is a easy way to validate user input client-sided. Maybe there are
better ways, which I don't know yet. Let me know ;)
I would recommend using text "(Please select a value)" only if a value must
be selected and there is no default one. If there is a default, you should
set it selected straight away. If the selection is optional, you should make
original text empty.

I agree that if defaults exist, we should set them straight away. What I am
concerning about are only required fields w/o defaults.
Well, you just revealed a lack of design in my application. Cause right now
when editing values with optional fields, it is not possible for users to
make selections empty ;). Thanks for that!
You can use an empty string as a value, or whatever else that will tell the
application that no selection has been made.

Hmm, empty string seems to be a good point to start ;)
not
No, I did not mean the table in the database. I mean the DataTable in the
Dataset the list is bound to. Or any other dotnet datasource for this
matter. And as far as database design is concern you are 100% right.

Ok, I think I misunderstood you in your prior posting.
Welcome to the web design world!

Thank you ;)

Regards,
Michael
 
Hi you can achieve this functionality by adding the following code in
your codebehind

Dropdown1.Items.Insert(0, "----Select an Item----")
Dropdown1.SelectedIndex = 0
Dropdown1.SelectedItem.Value = ""
 
hi,

You can achieve this functionality by adding the following code in your
codebehind----
 
You can acieve this functionality by adding the following code in your
codebehind area


Dropdown1.Items.Insert(0, "----Select an Item----")
Dropdown1.SelectedIndex = 0
Dropdown1.SelectedItem.Value = ""


Narendra
 
Back
Top