Jump to content
Xtreme .Net Talk

RepeaterItem.DataItem will not cast to DataRowView? [C#]


Recommended Posts

Posted

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."

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...