views:

45

answers:

2

I have a dropdown control, with some values I added in using the designer.

For example, "ANY", "Male", "Female".

The value for Male is set to M

The value for Female is set to F

The value for ANY is blank.

However, although it seems to be blank, I spent hours trying to debug a parse error...

And to my horror I discovered it wasn't blank at all! The value was set to "ANY".

I want the value to be blank, because my SQL query checks if the string is blank (or null).

My program breaks when it tries to put "ANY" into a varchar(1) for obvious reasons.

Am I doing something wrong? How can I make the default value blank?

+1  A: 

You need to set Value=""

<asp:DropDownList id="DropDownList1" runat="server">
   <asp:ListItem value="" Text="ANY">
   </asp:ListItem>
</asp:DropDownList>

If you still have your bug just set the value to 0 or one letter

JayJay
+1  A: 

You can have a blank value, you can reference it like this:

DropDownList1.SelectedValue;

OR

DropDownList1.Text;
rick schott
Doesn't the Text property get and set the same value that the SelectedValue property does?
Phaedrus
You are correct, I just read the docs. I will edit the answer.
rick schott