NewsRotator User Control Issue
Hi,
I have created a NewsRotator user control as specified in your online documentation but am having problems getting it to work at present. I receive the same error whenever I run this control under Sitefinity 4.1;
Object Reference not set to an instance of an object
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
This refers to the line line where Rad.Rotator1.DataSource is assigned
I have attempted to change this assignment in several ways, so that it
is not reading images, not reading from the Sitefinity database and even
just reading a simple list of text strings, but I continually get the
same error when I load the page where the control is installed
e.g.
IEnumerable<
NewsItem
> rotatorList
= App.WorkWith()
.NewsItems()
.Where(n => n.Status == ContentLifecycleStatus.Live)
.Get()
.Take(this.NewsLimit)
.ToList();
this.RadRotator1.DataSource = rotatorList;
Hi Paul,
Can you try casting the data source to list:
this
.RadRotator1.DataSource = rotatorList.ToList();
Hi,
I used the following which seemed to work:
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 );
this
.RadRotator1.DataSource = dataSource;
this
.RadRotator1.ItemDataBound +=
this
.RadRotator1_ItemDataBound;
this
.RadRotator1.DataBind();
Hello Paul,
Yes this will work because you have a .ToList()
call in the Fluent API method. Please note that this will make the Join in memory. The thing is that IEnumarable data source must be added to the page controls prior to databinding as was the problem in the first post.
Greetings,
Radoslav Georgiev
the Telerik team