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

Specidied cast is not valid

P: n/a
Jon
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
Nov 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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" <Jo*@discussions.microsoft.com> wrote in message
news:C6**********************************@microsof t.com...
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

Nov 19 '05 #2

P: n/a
Jon
Thanks Karl, that work, I can continue now :)

Jon

"Karl Seguin" wrote:
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" <Jo*@discussions.microsoft.com> wrote in message
news:C6**********************************@microsof t.com...
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


Nov 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.