Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > System.NullReferenceException:

Reply
Thread Tools

System.NullReferenceException:

 
 
Brian
Guest
Posts: n/a
 
      03-30-2005
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..

 
Reply With Quote
 
 
 
 
Marina
Guest
Posts: n/a
 
      03-30-2005
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?

"Brian" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
>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..
>



 
Reply With Quote
 
 
 
 
Brian Ciarcia
Guest
Posts: n/a
 
      03-30-2005
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..

*** Sent via Developersdex http://www.developersdex.com ***
 
Reply With Quote
 
Elton Wang
Guest
Posts: n/a
 
      03-30-2005
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
http://www.velocityreviews.com/forums/(E-Mail Removed)



>-----Original Message-----
>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..
>
>.
>

 
Reply With Quote
 
Sim0n Templar via DotNetMonster.com
Guest
Posts: n/a
 
      03-30-2005
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.

--
Message posted via http://www.dotnetmonster.com
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments