NewsRotator Tutorial - User Control

Posted by Community Admin on 04-Aug-2018 14:53

NewsRotator Tutorial - User Control

All Replies

Posted by Community Admin on 19-May-2015 00:00

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.

Posted by Community Admin on 20-May-2015 00:00

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?

This thread is closed