Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old May 27th, 2007, 03:20 AM
Authorized User
Join Date: May 2007
Location: , , .
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default Specified cast is not valid


I've got a gridview that has a checkbox as the first column, allowing the user to select that row.

I'm returning a value from the database to indicate whether the checkbox should be pre-checked...pretty standard, so I thought.

whenI do this:
<asp:TemplateField HeaderText="GetComplaint">
        <asp:CheckBox ID="chkAvail" runat="server" Checked='<%# Bind("ID") %>' />

It gives the error: System.InvalidCastException: Specified cast is not valid.

Please Help.


  #2 (permalink)  
Old May 27th, 2007, 08:51 PM
Friend of Wrox
Join Date: Feb 2006
Location: , , USA.
Posts: 116
Thanks: 0
Thanked 0 Times in 0 Posts


You need to check and make sure that the column "ID" in your data source is returning a valid boolean data type. Just by the name "ID" I would bet that you are binding to the wrong column, probably some primary key field. You need to insure that the values that you bind your checkbox's Checked property to are only "1" or "0". Look at the Checked properties data type. It is boolean.

Good luck.


Similar Threads
Thread Thread Starter Forum Replies Last Post
Specified cast is not valid. ayem Visual Studio 2008 1 September 8th, 2008 09:15 PM
Specified cast is not valid surajb Crystal Reports 0 January 12th, 2007 02:03 PM
Specified cast is not valid. abstar BOOK: ASP.NET Website Programming Problem-Design-Solution 2 March 31st, 2005 03:00 PM
"Specified cast is not valid" help BaBaBooey ASP.NET 1.0 and 1.1 Basics 2 November 23rd, 2004 12:12 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.