+1-888-365-2779
Try Now
More in this section

Forums / Sitefinity SDK / NewsRotator User Control Issue

NewsRotator User Control Issue

4 posts, 0 answered
  1. Paul
    Paul avatar
    9 posts
    Registered:
    11 Aug 2010
    18 Jul 2011
    Link to this post
    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?

     
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    21 Jul 2011
    Link to this post
    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 >>

  3. Paul
    Paul avatar
    9 posts
    Registered:
    11 Aug 2010
    21 Jul 2011
    Link to this post
    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
  4. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    25 Jul 2011
    Link to this post
    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 >>

4 posts, 0 answered