473,387 Members | 1,516 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,387 software developers and data experts.

compile error

LL
Hi,

How to fix this problem:

Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Specified cast is not valid.

Source Error:
Line 138: </ItemTemplate>
Line 139: <EditItemTemplate>
Line 140: <asp:CheckBox id=edit_Status runat="server" Checked='<%#
DataBinder.Eval(Container.DataItem, "Status")%>'>
Line 141: </asp:CheckBox>
Line 142: </EditItemTemplate>

Nov 15 '05 #1
13 3297
"LL" <li*******@hotmail.com> wrote in
news:eN**************@TK2MSFTNGP09.phx.gbl:
Hi,

How to fix this problem:

Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Specified cast is not
valid.

Source Error:
Line 138: </ItemTemplate>
Line 139: <EditItemTemplate>
Line 140: <asp:CheckBox id=edit_Status runat="server"
Checked='<%# DataBinder.Eval(Container.DataItem, "Status")%>'>
Line 141: </asp:CheckBox>
Line 142: </EditItemTemplate>


probably your StatusField isn'T of Type bool?

if it is nummeric (0,1) you could do this:
Checked='<%# 1==DataBinder.Eval(Container.DataItem, "Status")%>'>

if it'S text ("true", "false") you could do this:

Checked='<%# "true" == DataBinder.Eval(Container.DataItem, "Status")%>'>

I guess you got the idea ...
--
best regards

Peter Koen
-----------------------------------
MCAD, CAI/R, CAI/S, CASE/RS, CAT/RS
http://www.kema.at
Nov 15 '05 #2
LL
Hi,

If I change to GetSelectedIndex(1) , then it works.
Please help me on this error:
Specified cast is not valid.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Specified cast is not valid.

Source Error:
Line 131:
Line 132:<EditItemTemplate>
Line 133: <asp:DropDownList id=edit_AdminRights runat="server"
SelectedIndex='<%# GetSelectedIndex((int)DataBinder.Eval(Container.Da taItem,
"AdminRights")) %>'>
Line 134: <asp:ListItem Value="0" Selected="True">Read
Only</asp:ListItem>
Line 135: <asp:ListItem Value="1">Read/Edit</asp:ListItem>
Source File: C:\Project\test\Maintenance.aspx Line: 133

"Peter Koen" <koen-newsreply&snusnu.at> wrote in message
news:uW**************@TK2MSFTNGP11.phx.gbl...
"LL" <li*******@hotmail.com> wrote in
news:eN**************@TK2MSFTNGP09.phx.gbl:
Hi,

How to fix this problem:

Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Specified cast is not
valid.

Source Error:
Line 138: </ItemTemplate>
Line 139: <EditItemTemplate>
Line 140: <asp:CheckBox id=edit_Status runat="server"
Checked='<%# DataBinder.Eval(Container.DataItem, "Status")%>'>
Line 141: </asp:CheckBox>
Line 142: </EditItemTemplate>


probably your StatusField isn'T of Type bool?

if it is nummeric (0,1) you could do this:
Checked='<%# 1==DataBinder.Eval(Container.DataItem, "Status")%>'>

if it'S text ("true", "false") you could do this:

Checked='<%# "true" == DataBinder.Eval(Container.DataItem, "Status")%>'>

I guess you got the idea ...
--
best regards

Peter Koen
-----------------------------------
MCAD, CAI/R, CAI/S, CASE/RS, CAT/RS
http://www.kema.at

Nov 15 '05 #3
LL <li*******@hotmail.com> wrote:
If I change to GetSelectedIndex(1) , then it works.
Please help me on this error:
Specified cast is not valid.


That suggests that DataBinder.Eval(Container.DataItem,"AdminRights")
isn't returning an integer. Try writing to the debug log:

DataBinder.Eval(Container.DataItem,"AdminRights"). GetType()

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #4
LL
Thanks Jon.

It's 'Byte'.
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
LL <li*******@hotmail.com> wrote:
If I change to GetSelectedIndex(1) , then it works.
Please help me on this error:
Specified cast is not valid.


That suggests that DataBinder.Eval(Container.DataItem,"AdminRights")
isn't returning an integer. Try writing to the debug log:

DataBinder.Eval(Container.DataItem,"AdminRights"). GetType()

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #5
That would make a great movie title....."Once Byte en"
"LL" <li*******@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
Thanks Jon.

It's 'Byte'.
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
LL <li*******@hotmail.com> wrote:
If I change to GetSelectedIndex(1) , then it works.
Please help me on this error:
Specified cast is not valid.


That suggests that DataBinder.Eval(Container.DataItem,"AdminRights")
isn't returning an integer. Try writing to the debug log:

DataBinder.Eval(Container.DataItem,"AdminRights"). GetType()

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Nov 15 '05 #6
LL <li*******@hotmail.com> wrote:
It's 'Byte'.


Right. In that case, you need to either cast to byte, and all should be
well.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #7
Yes it will heal if you put a cast on it. It will get well.


"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
LL <li*******@hotmail.com> wrote:
It's 'Byte'.


Right. In that case, you need to either cast to byte, and all should be
well.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #8
LL
Hi,

How to fix this one:
(int) ((ListBox)E.Item.FindControl("edit_" + "AdminRights")).SelectedValue
error: '(int)' cannot be performed on '"0"'

How to get the
SelectedValue?

Thanks again.


"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
LL <li*******@hotmail.com> wrote:
It's 'Byte'.


Right. In that case, you need to either cast to byte, and all should be
well.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #9
LL <li*******@hotmail.com> wrote:
How to fix this one:
(int) ((ListBox)E.Item.FindControl("edit_" + "AdminRights")).SelectedValue
error: '(int)' cannot be performed on '"0"'

How to get the
SelectedValue?


Well I'd start by making your code more readably in the first place -
if you break that single line up into several, chances are it'll become
obvious.

That seems a strange compilation error to me, but SelectedValue returns
a string, not an integer. You'll need to use Int32.Parse or
Convert.ToInt32 in order to convert a string to an integer.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #10
ll
Thanks Jon!

How to assign the listbox's value to a command parameter?
myCommnd.Parameters["x"].Value = ((ListBox)E.Item.FindControl("edit_" +
"AdminRights")).SelectedValue?

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
LL <li*******@hotmail.com> wrote:
How to fix this one:
(int) ((ListBox)E.Item.FindControl("edit_" + "AdminRights")).SelectedValue error: '(int)' cannot be performed on '"0"'

How to get the
SelectedValue?


Well I'd start by making your code more readably in the first place -
if you break that single line up into several, chances are it'll become
obvious.

That seems a strange compilation error to me, but SelectedValue returns
a string, not an integer. You'll need to use Int32.Parse or
Convert.ToInt32 in order to convert a string to an integer.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #11
ll <li*******@hotmail.com> wrote:
How to assign the listbox's value to a command parameter?
myCommnd.Parameters["x"].Value = ((ListBox)E.Item.FindControl("edit_" +
"AdminRights")).SelectedValue?


I don't know off-hand, to be honest. I would *guess* that you don't
need the ".Value" bit there, but that's only a guess.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #12
ll
Thanks Jon.

I found it. The control is a "Dropdown" box not "ListBox". So when I run it.
got run time error: Invalid cast...
but why when I debug it. I can print the value out though ((ListBox)E....?


"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
ll <li*******@hotmail.com> wrote:
How to assign the listbox's value to a command parameter?
myCommnd.Parameters["x"].Value = ((ListBox)E.Item.FindControl("edit_" +
"AdminRights")).SelectedValue?


I don't know off-hand, to be honest. I would *guess* that you don't
need the ".Value" bit there, but that's only a guess.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #13
ll <li*******@hotmail.com> wrote:
I found it. The control is a "Dropdown" box not "ListBox". So when I run it.
got run time error: Invalid cast...
but why when I debug it. I can print the value out though ((ListBox)E....?


Again, break your long lines down a bit so each only does one thing -
then you'll be much more likely to be able to find the problem quickly.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #14

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

Similar topics

4
by: Danny Boelens | last post by:
Hi all, today I ran into a compile error after a compiler upgrade. I made a small example to demonstrate my compile error: template<typename T1, typename T2> class A {}; class B
5
by: Carmine Cairo | last post by:
Hi, I'm working on a project and today I've note a little problem during the compile fase. Here a little piece of code: // 1st version welldone = 0; size = p->getSize(); backbone = new...
5
by: Brice Prunier | last post by:
Here under 4 schemas i'm working with ( it may be long: sorry...) The context is the following : Resident.xsd imports Person.xsd and includes Common.xsd ( anonimous schema: no TargetNamespace )...
10
by: Chris LaJoie | last post by:
Our company has been developing a program in C# for some time now, and we haven't had any problems with it, but just last night something cropped up that has me, and everyone else, stumped. I...
6
by: Thomas Connolly | last post by:
I have 2 pages referencing the same codebehind file in my project. Originally the pages referenced separate code behind files. Once I changed the reference to the same file, everything worked...
0
by: Jim Heavey | last post by:
Internal Compiler Error: stage 'BEGIN' Hello, I had an application which was working just fine and I decided to modify all database access within the application to utilizie a new Namespace that I...
9
by: ThunderMusic | last post by:
Hi, I'd like to create a compile time error in my class... maybe there's a way already built in in the framework so I can achieve what I want... I have 2 constructors in my class. One of them...
4
by: tony | last post by:
Hello! My question is about calling this method CollectData below but I get a compile error that I shouldn't have because the type parameter is correct. The compile error is the following:...
5
by: wong_powah | last post by:
#include <vector> #include <iostream> using std::cout; using std::vector; enum {DATASIZE = 20}; typedef unsigned char data_t;
2
by: BruceWho | last post by:
I downloaded boost1.35.0 and built it with following command: bjam --toolset=msvc-7.1 --variant=release --threading=multi -- link=shared --with-system stage and it failed to compile, error...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
0
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,...
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...

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.