System.NullReferenceException:

B

Brian

i have a radiobuttonlist. I want to check to see if a button has been
selected then get the value.. This was my code;

----------------------------------------------------------------

Dim NewGender as String
if (Gender.SelectedItem.Value <> "") then
NewGender = Gender.SelectedItem.Value

else

NewGender = ""

end if

If nothing is selected, I get the following error..

System.NullReferenceException: Object reference not set to an instance
of an object.

thank in advance..
 
M

Marina

Yes, if no item is selected then you get the error. Wouldn't you expect to
get it if you are checking the Value property of SelectedItem, but
SelectedItem is null?
What is your question exactly?
 
B

Brian Ciarcia

I needed to check if there was a value or not, so I wouldn't get an
error when I posted the value..

I figured it out though.. i needed to to Gender.SelectedValue.. I am
kinda new to this, so I am still learning.. Thanks for your response..
 
E

Elton Wang

Hi Brian,

1. You can set a default value for radiobuttonlist.

2. Or you can

If Not Gender.SelectedItem Is Nothing Then
if (Gender.SelectedItem.Value <> "") then
' ...

End If



HTH

Elton Wang
(e-mail address removed)
 
S

Sim0n Templar via DotNetMonster.com

Brian,

I've been doing some research on radiobuttonlists and from what i've read
and the examples i've looked at, i have not yet found a way to handle an
"unselected" radiobuttonlist.

Are you trying to update a database or just trying to display what the user
has selected?

Also, i'd be interested to know if you have found a way to update a
database (even if it's a null value) if no items in a radiobuttonlist have
been selected.

Thanks.
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top