473,372 Members | 1,011 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,372 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 3666
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.