Click here to Skip to main content
15,914,163 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
hi.

iam using asp.net4 & sqlserver 2008r2 .

i have designed a registratoin form with the ASP.net formview.
one of my page title is :Gender that i have made it with Radiobuttonlist (man,woman)

then i have bounded it to database with Radiobuttonlist's data bind option(with Asp.net data bind facelity), but when i run the solution , after it create the
local host and goes to the browser , suddenly it will exit and throw an exception as follows:

++An exception of type 'System.NullReferenceException' occurred in App_Web_jygilfee.dll but was not handled in user code++

and :

++Object reference not set to an instance of an object++
with this title:

++nullReferenceException was unhandled by user code++

Code:

ASP.NET
<asp:Panel ID="Panel1" runat="server" Enabled='<%# Eval("Gender") %>'
                                               Visible="False">
    <asp:RadioButtonList ID="GenderRadioButton" runat="server" AutoPostBack="True"
         CausesValidation="True" RepeatDirection="Horizontal" SelectedIndex='<%# Eval("Gender") %>' SelectedValue='<%# Bind("Gender") %>'>
          <asp:ListItem Selected="True">man
          <asp:ListItem>woman
Posted
Updated 24-Jun-12 22:52pm
v2
Comments
Please post your total code, so that we can track the bug...
mohammad ehsan 25-Jun-12 4:37am    
this is the RadiobuttonList's section code:





<asp:Panel ID="Panel1" runat="server" Enabled='<%# Eval("Gender") %>'
Visible="False">
<asp:RadioButtonList ID="GenderRadioButton" runat="server" AutoPostBack="True"
CausesValidation="True" RepeatDirection="Horizontal"
SelectedIndex='<%# Eval("Gender") %>' SelectedValue='<%# Bind("Gender") %>'>
<asp:ListItem Selected="True">man
<asp:ListItem>woman
From the code I can make out that you may not be getting the value of "Gender" from the Database. Please make sure you get the value. Or else debug and check at each step.
Sergey Alexandrovich Kryukov 25-Jun-12 19:38pm    
What does it mean "running a solution"? There is no such thing. You can run an application, which is not the same. No, this is not just words, but the essential distinction.
--SA

1 solution

Object reference not set to an instance of an object

This error happens when you try to use a property or call a method of an object that is null. More details: here[^]

A simple use of Visual studio DEBUGGER can tell you the object because of which it is happening. Just look at the stack trace and put a debugger on that line. Check the objects of that line and see if any one is null and you are trying to use that objects property. Handle the same.

For now, do look at this to start with assuming value for 'Gender' is getting through:
HTML
Enabled='<%# Eval("Gender") %>'

Eval will get the string equivalent and not the boolean one. Setting it to a Boolean expecting property might cause issues.

BTW, I could not understand the point of having a enable proerty being set via an Eval here. That too when Panel is made hidden!
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 25-Jun-12 19:39pm    
Sure, a 5.
--SA
Sandeep Mewara 26-Jun-12 14:45pm    
Thanks SA.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900