Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   System.NullReferenceException: (http://www.velocityreviews.com/forums/t99620-system-nullreferenceexception.html)

Brian 03-30-2005 04:33 PM

System.NullReferenceException:
 
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..


Marina 03-30-2005 05:00 PM

Re: System.NullReferenceException:
 
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" <bciarcia@pepehazard.com> wrote in message
news:1112200428.271311.212350@l41g2000cwc.googlegr 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..
>




Brian Ciarcia 03-30-2005 05:08 PM

Re: System.NullReferenceException:
 
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 ***

Elton Wang 03-30-2005 05:13 PM

System.NullReferenceException:
 
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
elton_wang@hotmail.com



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


Sim0n Templar via DotNetMonster.com 03-30-2005 06:31 PM

Re: System.NullReferenceException:
 
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


All times are GMT. The time now is 04:39 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.