Modifying NewsRotator Sample to use custom field image selector
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
);
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.
I found the problem but will leave the thread open in case I have any more question. newsItem.GetValue(
Instead of this:
"Thumbnail")
Use this:
newsItem.GetValue<string>("Thumbnail")