Specidied 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
 
K

Karl Seguin

Jon,
If you are binding to a Hashtable, e.Item.DataItem is of type
DictionaryEntry

DictionaryEntry entry = (DictionaryEntry)e.Item.DataItem;
string key = (string)entry.Key;
sring value = (string)entry.Value;


of course this is assuming that your hashtable has strings inside of it..but
still, use DictionaryEntry and .Key and .Value to get the key and value
respectively.

Karl
 
G

Guest

Thanks Karl, that work, I can continue now :)

Jon

Karl Seguin said:
Jon,
If you are binding to a Hashtable, e.Item.DataItem is of type
DictionaryEntry

DictionaryEntry entry = (DictionaryEntry)e.Item.DataItem;
string key = (string)entry.Key;
sring value = (string)entry.Value;


of course this is assuming that your hashtable has strings inside of it..but
still, use DictionaryEntry and .Key and .Value to get the key and value
respectively.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/


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

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top