Click here to Skip to main content
15,889,335 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi ALL,

I have got an error in Line 16 in my website..
Object cannot be cast from DBNull to other types.



Here is the code:



XML
Line 14:                   <ItemTemplate>
Line 15:
Line 16:                 <asp:CheckBox ID="chkStatus" runat="server"
Line 17:                             AutoPostBack="true" OnCheckedChanged="chkStatus_OnCheckedChanged"
Line 18:                             Checked='<%# Convert.ToBoolean(Eval("active")) %>'
Posted
Comments
Sergey Alexandrovich Kryukov 5-Dec-13 12:07pm    
It looks like a complete answer to me.
—SA

1 solution

It looks like the problem is in Convert.ToBoolean(Eval("active")).

My guess is that the value of "active" in the database is null. You can't convert a null to a Boolean data type. You should check for a null value before you attempt Convert.ToBoolean.
 
Share this answer
 

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