By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,636 Members | 1,915 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,636 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.