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

I have a Checkbox in a Details View form in a asp.net web app. The form data source comes from a SQL table that has a column named Approved that is binded to the Checkbox. My problem is at runtime I get the error "Specified Cast is not valid".

Can someone give a solution to this issue?

Thanks in advance.

What I have tried:

on Page_Load Event I tried

foreach (DetailsViewRow DetailsViewRow in DetailsView1.Rows)
{
if (DetailsViewRow.Cells["Approved"].Value != null && (bool)DetailsViewRow.Cells["Approved"].Value)
{

}
else if (DetailsViewRow.Cells["Approved"].Value == null)
{

}
}
Posted
Updated 2-Nov-17 3:32am
Comments
Karthik_Mahalingam 1-Nov-17 23:20pm    
debug and check what is the value you are getting in
DetailsViewRow.Cells["Approved"].Value
GKP1992 1-Nov-17 23:51pm    
If you want to know if the checkbox is checked or not, why not use the Checked property?

Quote:
Can someone give a solution to this issue?
Yes, you'll need to debug it. The error means you are trying to cast something into something it is not. For example, the string "approved" into a boolean. We cannot run your code so we cannot see what any of the values are.

You'll want to start with finding out which line of code the error is pointing to. Then it should be very, very easy to figure out what is happening.
 
Share this answer
 
 
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