NewsRotator User Control Issue

Posted by Community Admin on 05-Aug-2018 16:56

NewsRotator User Control Issue

All Replies

Posted by Community Admin on 18-Jul-2011 00:00

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;

The rotatorList is read fine in this example but as soon as an attempt is made to assign to the RadRotator1 data source, the exception occurs. The rest of the code is as per the example, can you explain where I am going wrong with this?

 

Posted by Community Admin on 21-Jul-2011 00:00

Hi Paul,

Can you try casting the data source to list:

this.RadRotator1.DataSource = rotatorList.ToList();

Best wishes,
Radoslav Georgiev
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

Posted by Community Admin on 21-Jul-2011 00:00

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();

Thanks,
Paul

Posted by Community Admin on 25-Jul-2011 00:00

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

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

This thread is closed