473,698 Members | 2,361 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Specified cast is not valid.

Hello,

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.InvalidC astException: Specified cast is not valid.
Line 176.

Source Error:
Line 174:
Line 175:
Line 176: DataRowView drv = (DataRowView) e.Item.DataItem ;
Line 177:
Line 178: System.Web.UI.W ebControls.Imag e thumb =
(System.Web.UI. WebControls.Ima ge) e.Item.FindCont rol("thumbnail" );
Can somebody help me?

Thanks!
Nov 17 '05 #1
10 1784
You're casting a "DataItem" as a "DataRowVie w" - that's an invalid cast!!
hehehe - I know I sound like your error, but it's true. You can't pretend a
DataItem is a DataRowView..

"Arjen" <bo*****@hotmai l.com> wrote in message
news:bh******** **@news1.tilbu1 .nb.home.nl...
Hello,

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.InvalidC astException: Specified cast is not valid. Line 176.

Source Error:
Line 174:
Line 175:
Line 176: DataRowView drv = (DataRowView) e.Item.DataItem ;
Line 177:
Line 178: System.Web.UI.W ebControls.Imag e thumb =
(System.Web.UI. WebControls.Ima ge) e.Item.FindCont rol("thumbnail" );
Can somebody help me?

Thanks!

Nov 17 '05 #2
And now?

"Frank Drebin" <no*****@imsick ofspam.com> schreef in bericht
news:eU******** **************@ newssvr28.news. prodigy.com...
You're casting a "DataItem" as a "DataRowVie w" - that's an invalid cast!!
hehehe - I know I sound like your error, but it's true. You can't pretend a DataItem is a DataRowView..

"Arjen" <bo*****@hotmai l.com> wrote in message
news:bh******** **@news1.tilbu1 .nb.home.nl...
Hello,

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.InvalidC astException: Specified cast is not

valid.
Line 176.

Source Error:
Line 174:
Line 175:
Line 176: DataRowView drv = (DataRowView) e.Item.DataItem ;
Line 177:
Line 178: System.Web.UI.W ebControls.Imag e thumb =
(System.Web.UI. WebControls.Ima ge) e.Item.FindCont rol("thumbnail" );
Can somebody help me?

Thanks!


Nov 17 '05 #3

And now, you still can't. You can only coerce a variable to pretend it's a
different type - when they are close enough..

In the same way you couldn't do this:

TreeView objMyTree = (TreeView)strSo meString;

You can't cast things that are vastly different. There is no way to coerce a
string into representing a TreeView.

"Arjen" <bo*****@hotmai l.com> wrote in message
news:bh******** **@news1.tilbu1 .nb.home.nl...
And now?

"Frank Drebin" <no*****@imsick ofspam.com> schreef in bericht
news:eU******** **************@ newssvr28.news. prodigy.com...
You're casting a "DataItem" as a "DataRowVie w" - that's an invalid cast!! hehehe - I know I sound like your error, but it's true. You can't
pretend a
DataItem is a DataRowView..

"Arjen" <bo*****@hotmai l.com> wrote in message
news:bh******** **@news1.tilbu1 .nb.home.nl...
Hello,

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.InvalidC astException: Specified cast is not

valid.
Line 176.

Source Error:
Line 174:
Line 175:
Line 176: DataRowView drv = (DataRowView) e.Item.DataItem ;
Line 177:
Line 178: System.Web.UI.W ebControls.Imag e thumb =
(System.Web.UI. WebControls.Ima ge) e.Item.FindCont rol("thumbnail" );
Can somebody help me?

Thanks!



Nov 17 '05 #4
Put a breaking point at DataRowView drv = (DataRowView) e.Item.DataItem ;
Then Do a Quick Watch on e.item.DataItem or find the type of e.item.DataItem
and see what type it is
Then cast to that type
"Arjen" <bo*****@hotmai l.com> wrote in message
news:bh******** **@news1.tilbu1 .nb.home.nl...
And now?

"Frank Drebin" <no*****@imsick ofspam.com> schreef in bericht
news:eU******** **************@ newssvr28.news. prodigy.com...
You're casting a "DataItem" as a "DataRowVie w" - that's an invalid cast!! hehehe - I know I sound like your error, but it's true. You can't
pretend a
DataItem is a DataRowView..

"Arjen" <bo*****@hotmai l.com> wrote in message
news:bh******** **@news1.tilbu1 .nb.home.nl...
Hello,

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.InvalidC astException: Specified cast is not

valid.
Line 176.

Source Error:
Line 174:
Line 175:
Line 176: DataRowView drv = (DataRowView) e.Item.DataItem ;
Line 177:
Line 178: System.Web.UI.W ebControls.Imag e thumb =
(System.Web.UI. WebControls.Ima ge) e.Item.FindCont rol("thumbnail" );
Can somebody help me?

Thanks!



Nov 17 '05 #5
Here is the complete function:
private void myDataGrid_Item DataBound(objec t sender,
System.Web.UI.W ebControls.Data GridItemEventAr gs e) {

if (e.Item.ItemTyp e == ListItemType.It em || e.Item.ItemType ==
ListItemType.Al ternatingItem) {

DataRowView drv = (DataRowView) e.Item.DataItem ;

System.Web.UI.W ebControls.Imag e thumb = (System.Web.UI. WebControls.Ima ge)
e.Item.FindCont rol("thumbnail" );
thumb.Attribute s.Add("OnClick" , "SelectImag e('" + drv["itemId"].ToString()
+ "')");

}
}

May be this helps.





"MS News (MS ILM)" <sq**********@h otmail.com> schreef in bericht
news:up******** ******@TK2MSFTN GP09.phx.gbl...
Put a breaking point at DataRowView drv = (DataRowView) e.Item.DataItem ; Then Do a Quick Watch on e.item.DataItem or find the type of e.item.DataItem and see what type it is
Then cast to that type
"Arjen" <bo*****@hotmai l.com> wrote in message
news:bh******** **@news1.tilbu1 .nb.home.nl...
And now?

"Frank Drebin" <no*****@imsick ofspam.com> schreef in bericht
news:eU******** **************@ newssvr28.news. prodigy.com...
You're casting a "DataItem" as a "DataRowVie w" - that's an invalid cast!! hehehe - I know I sound like your error, but it's true. You can't pretend
a
DataItem is a DataRowView..

"Arjen" <bo*****@hotmai l.com> wrote in message
news:bh******** **@news1.tilbu1 .nb.home.nl...
> Hello,
>
> 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.InvalidC astException: Specified cast is not valid.
> Line 176.
>
> Source Error:
>
>
> Line 174:
> Line 175:
> Line 176: DataRowView drv = (DataRowView) e.Item.DataItem ;
> Line 177:
> Line 178: System.Web.UI.W ebControls.Imag e thumb =
> (System.Web.UI. WebControls.Ima ge) e.Item.FindCont rol("thumbnail" );
>
>
> Can somebody help me?
>
> Thanks!
>
>



Nov 17 '05 #6
I *think* in that scenario - that e is actually your DataRowView..

Set a breakpoint and add a watch to 'e' and see what it is, if it is a
DataRowView then you can just reference things as:

e["itemId"].ToString()

hth

"Arjen" <bo*****@hotmai l.com> wrote in message
news:bh******** **@news1.tilbu1 .nb.home.nl...
Here is the complete function:
private void myDataGrid_Item DataBound(objec t sender,
System.Web.UI.W ebControls.Data GridItemEventAr gs e) {

if (e.Item.ItemTyp e == ListItemType.It em || e.Item.ItemType ==
ListItemType.Al ternatingItem) {

DataRowView drv = (DataRowView) e.Item.DataItem ;

System.Web.UI.W ebControls.Imag e thumb = (System.Web.UI. WebControls.Ima ge) e.Item.FindCont rol("thumbnail" );
thumb.Attribute s.Add("OnClick" , "SelectImag e('" + drv["itemId"].ToString() + "')");

}
}

May be this helps.





"MS News (MS ILM)" <sq**********@h otmail.com> schreef in bericht
news:up******** ******@TK2MSFTN GP09.phx.gbl...
Put a breaking point at DataRowView drv = (DataRowView)

e.Item.DataItem ;
Then Do a Quick Watch on e.item.DataItem or find the type of

e.item.DataItem
and see what type it is
Then cast to that type
"Arjen" <bo*****@hotmai l.com> wrote in message
news:bh******** **@news1.tilbu1 .nb.home.nl...
And now?

"Frank Drebin" <no*****@imsick ofspam.com> schreef in bericht
news:eU******** **************@ newssvr28.news. prodigy.com...
> You're casting a "DataItem" as a "DataRowVie w" - that's an invalid

cast!!
> hehehe - I know I sound like your error, but it's true. You can't

pretend
a
> DataItem is a DataRowView..
>
> "Arjen" <bo*****@hotmai l.com> wrote in message
> news:bh******** **@news1.tilbu1 .nb.home.nl...
> > Hello,
> >
> > 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.InvalidC astException: Specified cast is

not > valid.
> > Line 176.
> >
> > Source Error:
> >
> >
> > Line 174:
> > Line 175:
> > Line 176: DataRowView drv = (DataRowView) e.Item.DataItem ;
> > Line 177:
> > Line 178: System.Web.UI.W ebControls.Imag e thumb =
> > (System.Web.UI. WebControls.Ima ge) e.Item.FindCont rol("thumbnail" );
> >
> >
> > Can somebody help me?
> >
> > Thanks!
> >
> >
>
>



Nov 17 '05 #7
string thetype = e.Item.DataItem .GetType();

What do you get
"Arjen" <bo*****@hotmai l.com> wrote in message
news:bh******** **@news1.tilbu1 .nb.home.nl...
When I change it to e["itemId"].ToString().
VS says:
Cannot apply indexing with [] to an expression of type
'System.Web.UI. WebControls.Dat aGridItemEventA rgs'

The debug says:
object DataGridItem.Da teItem
Gets or sets the data item represented by the
System.Web.UI.W ebControls.Data GridItem object in the
System.Web.UI.W ebControls.Data Grid

I don't know what to do now... you?
Thanks!



"Frank Drebin" <no*****@imsick ofspam.com> schreef in bericht
news:sj******** **************@ newssvr28.news. prodigy.com...
I *think* in that scenario - that e is actually your DataRowView..

Set a breakpoint and add a watch to 'e' and see what it is, if it is a
DataRowView then you can just reference things as:

e["itemId"].ToString()

hth

"Arjen" <bo*****@hotmai l.com> wrote in message
news:bh******** **@news1.tilbu1 .nb.home.nl...
Here is the complete function:
private void myDataGrid_Item DataBound(objec t sender,
System.Web.UI.W ebControls.Data GridItemEventAr gs e) {

if (e.Item.ItemTyp e == ListItemType.It em || e.Item.ItemType ==
ListItemType.Al ternatingItem) {

DataRowView drv = (DataRowView) e.Item.DataItem ;

System.Web.UI.W ebControls.Imag e thumb =

(System.Web.UI. WebControls.Ima ge)
e.Item.FindCont rol("thumbnail" );
thumb.Attribute s.Add("OnClick" , "SelectImag e('" +

drv["itemId"].ToString()
+ "')");

}
}

May be this helps.





"MS News (MS ILM)" <sq**********@h otmail.com> schreef in bericht
news:up******** ******@TK2MSFTN GP09.phx.gbl...
> Put a breaking point at DataRowView drv = (DataRowView)
e.Item.DataItem ;
> Then Do a Quick Watch on e.item.DataItem or find the type of
e.item.DataItem
> and see what type it is
> Then cast to that type
>
>
> "Arjen" <bo*****@hotmai l.com> wrote in message
> news:bh******** **@news1.tilbu1 .nb.home.nl...
> > And now?
> >
> >
> >
> >
> >
> > "Frank Drebin" <no*****@imsick ofspam.com> schreef in bericht
> > news:eU******** **************@ newssvr28.news. prodigy.com...
> > > You're casting a "DataItem" as a "DataRowVie w" - that's an invalid > cast!!
> > > hehehe - I know I sound like your error, but it's true. You can't > pretend
> > a
> > > DataItem is a DataRowView..
> > >
> > > "Arjen" <bo*****@hotmai l.com> wrote in message
> > > news:bh******** **@news1.tilbu1 .nb.home.nl...
> > > > Hello,
> > > >
> > > > 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.InvalidC astException: Specified cast

is not
> > > valid.
> > > > Line 176.
> > > >
> > > > Source Error:
> > > >
> > > >
> > > > Line 174:
> > > > Line 175:
> > > > Line 176: DataRowView drv = (DataRowView) e.Item.DataItem ;
> > > > Line 177:
> > > > Line 178: System.Web.UI.W ebControls.Imag e thumb =
> > > > (System.Web.UI. WebControls.Ima ge) e.Item.FindCont rol("thumbnail" ); > > > >
> > > >
> > > > Can somebody help me?
> > > >
> > > > Thanks!
> > > >
> > > >
> > >
> > >
> >
> >
>
>



Nov 17 '05 #8
> I *think* in that scenario - that e is actually your DataRowView.

"e" is an instance of DataGridItemEve ntArgs. "e.Item" is the member to look
at. It can be one of several possible types, such as a heading section, a
footer section, or a data row. However, setting a breakpoint and doing a
watch should indeed revela what e.Item is.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Neither a follower nor a lender be.

"Frank Drebin" <no*****@imsick ofspam.com> wrote in message
news:sj******** **************@ newssvr28.news. prodigy.com...
I *think* in that scenario - that e is actually your DataRowView..

Set a breakpoint and add a watch to 'e' and see what it is, if it is a
DataRowView then you can just reference things as:

e["itemId"].ToString()

hth

"Arjen" <bo*****@hotmai l.com> wrote in message
news:bh******** **@news1.tilbu1 .nb.home.nl...
Here is the complete function:
private void myDataGrid_Item DataBound(objec t sender,
System.Web.UI.W ebControls.Data GridItemEventAr gs e) {

if (e.Item.ItemTyp e == ListItemType.It em || e.Item.ItemType ==
ListItemType.Al ternatingItem) {

DataRowView drv = (DataRowView) e.Item.DataItem ;

System.Web.UI.W ebControls.Imag e thumb = (System.Web.UI. WebControls.Ima ge)
e.Item.FindCont rol("thumbnail" );
thumb.Attribute s.Add("OnClick" , "SelectImag e('" +

drv["itemId"].ToString()
+ "')");

}
}

May be this helps.





"MS News (MS ILM)" <sq**********@h otmail.com> schreef in bericht
news:up******** ******@TK2MSFTN GP09.phx.gbl...
Put a breaking point at DataRowView drv = (DataRowView)

e.Item.DataItem ;
Then Do a Quick Watch on e.item.DataItem or find the type of

e.item.DataItem
and see what type it is
Then cast to that type
"Arjen" <bo*****@hotmai l.com> wrote in message
news:bh******** **@news1.tilbu1 .nb.home.nl...
> And now?
>
>
>
>
>
> "Frank Drebin" <no*****@imsick ofspam.com> schreef in bericht
> news:eU******** **************@ newssvr28.news. prodigy.com...
> > You're casting a "DataItem" as a "DataRowVie w" - that's an invalid
cast!!
> > hehehe - I know I sound like your error, but it's true. You can't
pretend
> a
> > DataItem is a DataRowView..
> >
> > "Arjen" <bo*****@hotmai l.com> wrote in message
> > news:bh******** **@news1.tilbu1 .nb.home.nl...
> > > Hello,
> > >
> > > 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.InvalidC astException: Specified cast
is not
> > valid.
> > > Line 176.
> > >
> > > Source Error:
> > >
> > >
> > > Line 174:
> > > Line 175:
> > > Line 176: DataRowView drv = (DataRowView) e.Item.DataItem ;
> > > Line 177:
> > > Line 178: System.Web.UI.W ebControls.Imag e thumb =
> > > (System.Web.UI. WebControls.Ima ge)

e.Item.FindCont rol("thumbnail" ); > > >
> > >
> > > Can somebody help me?
> > >
> > > Thanks!
> > >
> > >
> >
> >
>
>



Nov 17 '05 #9
"Arjen" <bo*****@hotmai l.com> wrote
Line 176: DataRowView drv = (DataRowView) e.Item.DataItem ;

I use now a datagrid and the IBS a datalist.

Some body else a solution?


Arjen,
If you use a DataSet to bind the DataList, then that is the correct syntax.

However, if you use a SqlDataReader to bind, then you must cast the
DataItem to a System.Data.Com mon.DbDataRecor d.
e.g.
System.Data.Com mon.DbDataRecor d dbDataRecord =
(System.Data.Co mmon.DbDataReco rd) e.Item.DataItem ;
String s = dbDataRecord.Ge tString(0);

--

Thanks,
Carl Prothman
Microsoft ASP.NET MVP
http://www.able-consulting.com

Nov 17 '05 #10

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

Similar topics

0
3630
by: Tao | last post by:
I just upgraded .NET framework to 1.1 and VS.Net to 2003 version and tried to test it out. I created an ASP.NET project using the wizard and tried to run it by hitting "F5". I got an exception: "Specified cast is not valid." The only thing i put there was a "test this." inside the form. What might be the problem here? Thanks in advance. The Exception:
4
7035
by: Tyro | last post by:
Can someone shed some light on my error here? Thanks! Specified cast is not valid. Exception Details: System.InvalidCastException: Specified cast is not valid. Source Error: Stack Trace:
3
10509
by: PK9 | last post by:
I am looking for assistance in pinpointing the cause of the following exception. I am getting a "Specified Cast is not valid" exception on my page. I am trying to populate a datagrid. One of my columns is a template column where I'd like to evaluate the data brought back from the db and populate the column with a "Y" or "N" depending on the value in the db. Here is the code that is causing it as well as the error (below). ERROR...
2
3090
by: Fabian | last post by:
Hi, I work with asp.net 2.0 and I have a intermittent error, only happens a few times a day. In the page I evaluate a Query String and then I get data form a database. The code snipped: try {
3
2179
by: VB Programmer | last post by:
I am setting up forms authentication. In my code I keep getting this error. Any ideas? Error.... Server Error in '/LandOLots' Application. --------------------------------------------------------------------------------
0
623
by: QA | last post by:
I am using a Business Scorecard Accelarator in a Sharepoint Portal 2003 using SQL Server 2005 I am getting the following error: Error,5/7/2005 10:50:14 AM,580,AUE1\Administrator,"Specified cast is not valid.","Microsoft.BusinessIntelligence.Scorecard.ScorecardException: Specified cast is not valid. ---> Microsoft.BusinessIntelligence.Scorecard.ScorecardException: Specified cast is not valid. ---> System.InvalidCastException: Specified...
0
1620
by: Alan Z. Scharf | last post by:
this question in datagrid group for several days with no repsonse. I'm hoping for an answer her because of greater activity in this group. No cross-posting intended. Thanks. ----------------------------------------------------------- Server VS.NET 2003 SQLServer 2000 IIS 66.0
8
4266
by: Gamma | last post by:
I'm trying to inherit subclass from System.Diagnostics.Process, but whenever I cast a "Process" object to it's subclass, I encounter an exception "System.InvalidCastException" ("Specified cast is not valid"). How do I fix it ? using System.Diagnostics; .. .. class NewProcess: Process {
3
12433
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)
2
8779
by: vinrin | last post by:
Thank for your answer. :-) call CheckEmptyNode (treeview) public void CheckEmptyNode( Object N ) { Microsoft.Web.UI.WebControls.TreeNode menuNode = null; Microsoft.Web.UI.WebControls.TreeNode iNode = null;
0
8674
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
8603
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9157
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...
0
9027
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8861
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
5860
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
4369
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
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3046
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.