How do I test for null or empty value?

  • Thread starter Thread starter jm
  • Start date Start date
J

jm

I have a dropdownlist.

In my page_load I have:

myvariable as integer
myvariable = myddl.selectedvalue

I get "Input string was not in a correct format."

The I know my data and it is supposed to be a number. In reality,
however, because this is a fresh load (not a postback), the value is
empty for the selectedvalue and it is causing the error. I have to
have this load in the nonpostback. Since the value of the
dropdownlist is empty, nothing, or null, how do I test for this? I
cannot find it. Thank you.
 
Problem is you may not assign a Null (SelectedValue when nothing is
selected) to an integer variable

You may do

If myddl.SelectedIndex <> -1 Then ' something is selected
myvariable = myddl.SelectedValue
End If

Regards
Jose
 
if(blah != null)
{
}


BUT, you may simply want to only have the value read if it's a postback....
if(IsPostBack())
{
.....get values
}
else
{
....dont....
}
 
Back
Top