473,766 Members | 2,023 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:HyperLin k ID="HyperLink1 "
runat="server"
NavigateUrl='<% #
Eval("c2Hyperli nk1Link") %>'
Target="_blank"
Text='<%#
Eval("c2Hyperli nk1Text") %>'
Visible='<%#
Eval("c2Hyperli nk1Visible") %>' ></asp:HyperLink>

This code runs without error:

<asp:HyperLin k ID="HyperLink1 "
runat="server"
NavigateUrl='<% #
Eval("c2Hyperli nk1Link") %>'
Target="_blank"
Text='<%#
Eval("c2Hyperli nk1Text") %>'
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 3698
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******@dslex treme.comwrote in message
news:%2******** ********@TK2MSF TNGP02.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:HyperLin k ID="HyperLink1 "
runat="server"
NavigateUrl='<% #
Eval("c2Hyperli nk1Link") %>'
Target="_blank"
Text='<%#
Eval("c2Hyperli nk1Text") %>'
Visible='<%#
Eval("c2Hyperli nk1Visible") %>' ></asp:HyperLink>

This code runs without error:

<asp:HyperLin k ID="HyperLink1 "
runat="server"
NavigateUrl='<% #
Eval("c2Hyperli nk1Link") %>'
Target="_blank"
Text='<%#
Eval("c2Hyperli nk1Text") %>'
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("c2H yperlink1Visibl e"), 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:HyperLin k ID="HyperLink1 "
runat="server"
NavigateUrl='<% #
Eval("c2Hyperli nk1Link") %>'
Target="_blank"
Text='<%#
Eval("c2Hyperli nk1Text") %>'
Visible='<%#
Eval("c2Hyperli nk1Visible") %>' ></asp:HyperLink>

This code runs without error:

<asp:HyperLin k ID="HyperLink1 "
runat="server"
NavigateUrl='<% #
Eval("c2Hyperli nk1Link") %>'
Target="_blank"
Text='<%#
Eval("c2Hyperli nk1Text") %>'
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.netNoS pamMwrote in
message news:eX******** ******@TK2MSFTN GP04.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******@dslex treme.comwrote in message
news:%2******** ********@TK2MSF TNGP02.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:HyperLi nk ID="HyperLink1 "
runat="server"
NavigateUrl='<% #
Eval("c2Hyperl ink1Link") %>'
Target="_blank"
Text='<%#
Eval("c2Hyperl ink1Text") %>'
Visible='<%#
Eval("c2Hyperl ink1Visible") %>' ></asp:HyperLink>

This code runs without error:

<asp:HyperLi nk ID="HyperLink1 "
runat="server"
NavigateUrl='<% #
Eval("c2Hyperl ink1Link") %>'
Target="_blank"
Text='<%#
Eval("c2Hyperl ink1Text") %>'
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
1975
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 not valid" exception thrown. How can it not be valid when that's all the Items collection should contain? I tried using a while loop starting with Items.GetFirst(), then GetNext() but it only gets/prints the first item then loops forever...
0
1508
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 get a "Specified cast not valid!" error... MyDocumentDesigner FDDesigner = ((MyDocumentDesigner)DHost.GetDesigner((IComponent)CForm));
8
1803
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 along the lines of did you check this, have you did this, or this is the wrong way of doing this. I can access the CColPositions and the CPosition class, but when I try to use the two classes in a For...Next loop I get the error message above. ...
4
3839
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 absolutely no added functionality to it.
4
1828
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 Cast is not valid" error. I guess this makes sense since the .count item is a short, but I have dimed x as short. Any ideas. please :roll: Dim x As Short Dim objWinfaxSend As New wfxctl32.COleCoverPages x = objWinfaxSend.Count()
3
3200
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 index 0. This code hasn't been changed in months and it has never had this problem before... Thanks for any help you guys can give me!
2
1595
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, outlook.ContactItem) Do While TypeName(OLCont) <> "Nothing" OLRow = OLTable.NewRow OLRow(0) = 0 OLRow(1) = IIf(OLCont.FirstName Is Nothing, "", OLCont.FirstName) OLRow(2) =...
3
12435
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: ====================== Message: Specified cast is not valid. Type: System.InvalidCastException Source: System.Data.Linq TargetSite: Boolean TryCreateKeyFromValues(System.Object, V ByRef)
11
6901
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 actually populating a user control dynamically. And the problem arises when i try to populate it with values. and the code runs again after 30 or more seconds to get updated values and so on.. The code is given below This is actually the user control...
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10168
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9959
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9837
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6651
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5279
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.