How do I test for null or empty value?

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.
 
J

Jose Marcenaro

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
 
C

Curt_C [MVP]

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....
}
 

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

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top