473,398 Members | 2,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Please help: "Specified cast is not valid" error when binding the Visible propery of a hyperlink control

Using a GridView, I get a "Specified cast is not valid" error when binding
the Visible propery of a hyperlink control to a DataTable text field. The
error goes away if I replace the data binding statement with "true" or
"false". This code causes the error:

<asp:HyperLink ID="HyperLink1"
runat="server"
NavigateUrl='<%#
Eval("c2Hyperlink1Link") %>'
Target="_blank"
Text='<%#
Eval("c2Hyperlink1Text") %>'
Visible='<%#
Eval("c2Hyperlink1Visible") %>' ></asp:HyperLink>

This code runs without error:

<asp:HyperLink ID="HyperLink1"
runat="server"
NavigateUrl='<%#
Eval("c2Hyperlink1Link") %>'
Target="_blank"
Text='<%#
Eval("c2Hyperlink1Text") %>'
Visible="true" >'
></asp:HyperLink>
I do not understand this, because in both cases the Visible property
receives the same text value, "true". Any suggestions or ideas will be
greatly appreciated.

Thanks,

Keith
Sep 19 '06 #1
3 3672
It is seeing "true" (string) not true (boolean), or visa versa. You will
have to cast out the value as the correct type. Easiest way is to alter the
SQL Statement that creates the value and cast there, as you will not have to
change your binding at all.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*************************************************
Think outside of the box!
*************************************************
"keithb" <kb******@dslextreme.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
Using a GridView, I get a "Specified cast is not valid" error when binding
the Visible propery of a hyperlink control to a DataTable text field. The
error goes away if I replace the data binding statement with "true" or
"false". This code causes the error:

<asp:HyperLink ID="HyperLink1"
runat="server"
NavigateUrl='<%#
Eval("c2Hyperlink1Link") %>'
Target="_blank"
Text='<%#
Eval("c2Hyperlink1Text") %>'
Visible='<%#
Eval("c2Hyperlink1Visible") %>' ></asp:HyperLink>

This code runs without error:

<asp:HyperLink ID="HyperLink1"
runat="server"
NavigateUrl='<%#
Eval("c2Hyperlink1Link") %>'
Target="_blank"
Text='<%#
Eval("c2Hyperlink1Text") %>'
Visible="true" >'
</asp:HyperLink>

I do not understand this, because in both cases the Visible property
receives the same text value, "true". Any suggestions or ideas will be
greatly appreciated.

Thanks,

Keith

Sep 19 '06 #2
What if your data column has value of Null?
Make sure you are getting True/False value out of database.

Try convert value to Boolean explicitly

Visible='<%#
Ctype(Eval("c2Hyperlink1Visible"), Boolean) %>' ></asp:HyperLink>

--
Programmer
"keithb" wrote:
Using a GridView, I get a "Specified cast is not valid" error when binding
the Visible propery of a hyperlink control to a DataTable text field. The
error goes away if I replace the data binding statement with "true" or
"false". This code causes the error:

<asp:HyperLink ID="HyperLink1"
runat="server"
NavigateUrl='<%#
Eval("c2Hyperlink1Link") %>'
Target="_blank"
Text='<%#
Eval("c2Hyperlink1Text") %>'
Visible='<%#
Eval("c2Hyperlink1Visible") %>' ></asp:HyperLink>

This code runs without error:

<asp:HyperLink ID="HyperLink1"
runat="server"
NavigateUrl='<%#
Eval("c2Hyperlink1Link") %>'
Target="_blank"
Text='<%#
Eval("c2Hyperlink1Text") %>'
Visible="true" >'
></asp:HyperLink>

I do not understand this, because in both cases the Visible property
receives the same text value, "true". Any suggestions or ideas will be
greatly appreciated.

Thanks,

Keith
Sep 19 '06 #3
The data comes from a DataTable that is defined by an XSD file. I see no way
of defining the data field as Boolean. It looks like all of the fields are
text.

Thanks,

Keith
"Cowboy (Gregory A. Beamer)" <No************@comcast.netNoSpamMwrote in
message news:eX**************@TK2MSFTNGP04.phx.gbl...
It is seeing "true" (string) not true (boolean), or visa versa. You will
have to cast out the value as the correct type. Easiest way is to alter
the SQL Statement that creates the value and cast there, as you will not
have to change your binding at all.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*************************************************
Think outside of the box!
*************************************************
"keithb" <kb******@dslextreme.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>Using a GridView, I get a "Specified cast is not valid" error when
binding the Visible propery of a hyperlink control to a DataTable text
field. The error goes away if I replace the data binding statement with
"true" or "false". This code causes the error:

<asp:HyperLink ID="HyperLink1"
runat="server"
NavigateUrl='<%#
Eval("c2Hyperlink1Link") %>'
Target="_blank"
Text='<%#
Eval("c2Hyperlink1Text") %>'
Visible='<%#
Eval("c2Hyperlink1Visible") %>' ></asp:HyperLink>

This code runs without error:

<asp:HyperLink ID="HyperLink1"
runat="server"
NavigateUrl='<%#
Eval("c2Hyperlink1Link") %>'
Target="_blank"
Text='<%#
Eval("c2Hyperlink1Text") %>'
Visible="true" >'
></asp:HyperLink>

I do not understand this, because in both cases the Visible property
receives the same text value, "true". Any suggestions or ideas will be
greatly appreciated.

Thanks,

Keith


Sep 19 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Jim H | last post by:
I am trying to go through my Outlook (2003) address book. The code goes through the Items list and prints all the last names but after it hits 114 (out or 126 contacts) I get a "sepcified cast is...
0
by: Özden Irmak | last post by:
Hello, In my application, I've to cast DocumentDesigner class to my own derived class,MyDocumentDesigner, in order to reach the protected properties in DocumentDesigner class. But everytime I...
8
by: Charles | last post by:
I do not understand why I am getting a "Specified cast is not valid" error, since it has worked before. Something has changed and I am not really sure what it could be. I am looking for something...
4
by: Mike Cooper | last post by:
There is something about inherited classes I evidently don't know... I wrote the following class: Class Class1 inherits System.Windows.Forms.DataGridTextBoxColumn End Class There is...
4
by: redwebgeek | last post by:
Please help me. ANY guess or ideas welcome I am trying to list the types of coverpages available in winfax 10. I have the imports at the top of the page. Every time I run this I get a "Specified...
3
by: Jayyde | last post by:
Not sure why all of a sudden this line of code: cmbProductCategoryTreeDisplayName.SelectedIndex = 0; is producing a "Specified cast is not valid error". In the watch it has 1 item in it at...
2
by: vijayasingh | last post by:
I am trying to take contacts data from out look and Synchronize with our database. I am using .net 1.1 framework. iam using following code. OLCont = MyOLList.GetLast 'CType(item,...
3
by: =?Utf-8?B?UGF1bCBQcmV3ZXR0?= | last post by:
I'm attempting to use LINQ to insert a record into a child table and I'm receiving a "Specified cast is not valid" error that has something to do w/ the keys involved. The stack trace is: ...
11
by: Ahmedhussain | last post by:
hey everyone... I have a code which gives me this error. Error : Cross-thread operation not valid: Control 'textBox1' accessed from a thread other than the thread it was created on. I am...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.