NewsRotator Tutorial - User Control
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.
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?