fizzled Posted September 20, 2005 Posted September 20, 2005 I'm attempting to use the following code to conditionally drop a link inside a Repeater, and from what I've read everywhere, I should be able to cast the RepeaterItem.DataItem to a DataRowView to access the current row of information so I can decide if I need a link or not. Does anyone see why this isn't working? private void rptrActiveBlogs_ItemDataBound (object Sender, RepeaterItemEventArgs e) { if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem)) { [color=red]DataRowView drvCurrent = (DataRowView) e.Item.DataItem;[/color] Literal litAuthor = (Literal) e.Item.FindControl("litBlogAuthor"); if (drvCurrent["AuthorEmail"].ToString().Length == 0) { litAuthor.Text = drvCurrent["AuthorName"].ToString(); } else { litAuthor.Text = "<a href=\"mailto:" + drvCurrent["AuthorEmail"].ToString() + "\" title=\"Contact " + drvCurrent["AuthorName"].ToString() + "\">" + drvCurrent["AuthorName"].ToString() + "</a>"; } } } The error occurs on the line in red. The error specifically says "Specified cast is not valid." Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.