specified cast is not valid

G

Guest

Hello all,

Can some please help with an error I'm having. I'm binding a Hashtable to a
Repeater and on the ItemDataBound event i have this code:

if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
DataRowView dataRowView = (DataRowView)e.Item.DataItem;

string j = dataRowView[0].ToString();
}

but I'm getting the error, "specified cast is not valid".

at the below line:

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

Thanks all.

Jon
 
M

Miha Markic [MVP C#]

Hi Jon,

Try this:
object dataRowView = (DataRowView)e.Item.DataItem

and then inspect the object dataRowView in a debugger - it will tell you the
type.
 
G

Guest

Thanks for the reply <iha, the below line of code fixed it:

DictionaryEntry dataRowView = (DictionaryEntry)e.Item.DataItem;

Thanks,

Jon

Miha Markic said:
Hi Jon,

Try this:
object dataRowView = (DataRowView)e.Item.DataItem

and then inspect the object dataRowView in a debugger - it will tell you the
type.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
SLODUG - Slovene Developer Users Group
www.rthand.com

Jon said:
Hello all,

Can some please help with an error I'm having. I'm binding a Hashtable to
a
Repeater and on the ItemDataBound event i have this code:

if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
DataRowView dataRowView = (DataRowView)e.Item.DataItem;

string j = dataRowView[0].ToString();
}

but I'm getting the error, "specified cast is not valid".

at the below line:

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

Thanks all.

Jon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top