+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / NewsRotator Tutorial - User Control

NewsRotator Tutorial - User Control

2 posts, 0 answered
  1. David
    David avatar
    114 posts
    Registered:
    19 Jul 2012
    19 May 2015
    Link to this post

    I am trying to follow the NewsRotator example using a User Control, but during the item databind the following command gives a object reference not set to an instance of a object error.

    NewsItem newsItem = (NewsItem)TypeDescriptor.GetProperties(e.Item.DataItem)["NewsItem"].GetValue(e.Item.DataItem);

    I am binding the news items using this:

    var news = App.WorkWith()
    .NewsItems()
    .Get().Take(5)
    .ToList();
    RadRotator1.DataSource = news;
    RadRotator1.ItemDataBound += new RadRotatorEventHandler(RadRotator1_ItemDataBound);
    RadRotator1.DataBind();

    Which seems to work as I can write a simple for loop for news and get the titles of the news items.

  2. David
    David avatar
    114 posts
    Registered:
    19 Jul 2012
    20 May 2015
    Link to this post

    So in order to get this working I had to change this:

    NewsItem newsItem = (NewsItem)TypeDescriptor.GetProperties(e.Item.DataItem)["NewsItem"].GetValue(e.Item.DataItem);

    To this:

    NewsItem newsItem = (NewsItem) e.Item.DataItem;

     

    My questions would be why doesn't the first statement work for me as this was used in the example, the second would be if you can simply cast the dataitem to a newsitem, why not just do it that way?

2 posts, 0 answered