More in this section
Forums / Sitefinity SDK / Modifying NewsRotator Sample to use custom field image selector

Modifying NewsRotator Sample to use custom field image selector

The forums are in read-only mode. In case that you want to directly contact the Progress Sitefinity team use the support center. In our Google Plus group you can find more than one thousand Sitefinity developers discussing different topics. For the Stack Overflow threads don’t forget to use the “Sitefinity” tag.
2 posts, 0 answered
  1. David
    David avatar
    99 posts
    Registered:
    06 Sep 2012
    01 Nov 2011
    Link to this post
    Problem:
    The problem I am having is that I am not able to retrieve a custom field value added to the News module. I am trying to retreive the value  in the RadRotator1_ItemDataBound event.

    Objective
    To use a thumbnail selector added to the News Module, in combination with the SDK NewsRotator Sample. I successully implemented a thumbnail selector as a custom field by following the article:

     http://www.sitefinity.com/blogs/slavoingilizov/posts/11-09-09/extend_the_image_selector_for_content_items_with_filtering_by_album.aspx


    I then modified the dataSource in the NewsRotator Sample

    Old DataSource

     

    var dataSource = App.WorkWith().NewsItems()  

    .Where(n => n.Status ==  ContentLifecycleStatus.Live)

     .Get().Take(this.NewsLimit)

     .ToList()

    .Join(App.WorkWith().Images()

     .Get()

    .Where(i => i.Parent.Title == "Thumbnails" && i.Status == ContentLifecycleStatus.Live),

     item => item.Title.Value,

    image => image.Title.Value,

    (item, image) =>

     new { NewsItem = item, NewsImage = image }  

    );


    New DataSource

     

    var dataSource = App.WorkWith().NewsItems()

    .Where(n => n.Status == ContentLifecycleStatus.Live)

    .Get().Take(this.NewsLimit);

    After modify the datasource the line of code that gets the news item in RadRotator1_ItemDataBound stopped working. I'm not sure if the following was the correct thing to do, however, it did get rid of an error. I changed the following line of code.

    Old line of code

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

     

    New line of code

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

     
    At this point the NewsRotator is functional except that it does not display images.

    Where it's not working
    In RadRotator1_ItemDataBound I added the following code

    if
    (newsItem.GetValue("Thumbnail") != null)

    {

        string thumbnail = newsItem.GetValue("Thumbnail").ToString();

    }

    The problem is that newsItem.GetValue("Thumbnail") is always returning null.

  2. David
    David avatar
    99 posts
    Registered:
    06 Sep 2012
    01 Nov 2011
    Link to this post
    I found the problem but will leave the thread open in case I have any more question.

    Instead of this:

    newsItem.GetValue(

    "Thumbnail"

    Use this:

    newsItem.GetValue<
    string>("Thumbnail")

2 posts, 0 answered