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

Forums / Developing with Sitefinity / NewsRotator without using image

NewsRotator without using image

2 posts, 0 answered
  1. JingYuan
    JingYuan avatar
    12 posts
    Registered:
    18 Jul 2011
    16 Aug 2011
    Link to this post
    Hi all I know there is NewsRotator Sample.
    Unfortunately, in this example, the NewsRotator require a image to work. I am trying to make a NewsRotator + NewsTicker without having to create/upload a image for each news_items link.

    When I accessing the DB (sf_news_items) in an attempt to get the URL link to each news_items, I find that I can only get a UrlName which is not sufficient to get to the correct news_items from my NewsRotator. To make matter worse, I manually edited the published date for some of the news_items and cannot trace how sitefinity maintain the links to each news_items without using image.

    attached is mine ascx files which i using for my NewsRotator. Is creating a image a must for linking of news_items?
    Result of my NavigateUrl: <mysite>/<projectname>/<ascx folder>/<UrlName>
    Correct NavigateUrl: <mysite>/<projectname>/<news_items path>/<year>/<month>/<date>/<UrlName>

    NewsTicker.ascx
    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="NewsTicker.ascx.cs" Inherits="NewsTicker" %>
     
    <div class="container">
        <div id="news_announcements" class="news_announcements">
            <div id="news_announcements_left"><strong>News & Announcements</strong></div>
            <div id="news_announcements_right">
                <telerik:RadRotator ID="RadRotator1" runat="server" height="26px" width="550px" ItemHeight="26px" ItemWidth="550px" RotateType="SlideShowButtons" ScrollDuration="1" FrameDuration="7000"
                    OnItemDataBound="RadRotator1_ItemDataBound">
                    <ControlButtons LeftButtonID="homenews1_btn_news_Prev" RightButtonID="homenews1_btn_news_Next" />
                    <ItemTemplate>
                        <asp:HyperLink runat="server" ID="newsLink" NavigateUrl='<%# DataBinder.Eval(Container.DataItem, "UrlName") %>'>
                            <telerik:RadTicker ID="Radticker1" runat="server"
                                Loop="true"
                                TickSpeed="50">
                                <items>                   
                                    <telerik:RadTickerItem Text='<%# Eval("Title").ToString().Substring(0,Math.Min(80,Eval("Title").ToString().Length)) + " ... (" + Eval("PublicationDate", "{0:dd MMM yyyy}") + ")"%>' />
                                </items>
                            </telerik:RadTicker>
                        </asp:HyperLink>
                    </ItemTemplate>
                </sf:RadRotator>
            </div>
            <div id="news_announcements_view"><a href="../newsroom" id="news_announcements_view">View All News</a></div>
        </div>
    </div>

    NewsTicker.ascx.cs
    using System;
    using System.Data;
    using System.Collections;
    using System.Collections.Generic;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.ComponentModel;
    using System.Linq;
    using System.Text;
    using System.Web;
    using Telerik.Web.UI;
    using Telerik.Sitefinity;
    using Telerik.Sitefinity.Web.UI;
    using Telerik.Sitefinity.GenericContent.Model;
    using Telerik.Sitefinity.Modules;
    using Telerik.Sitefinity.Modules.News;
    using Telerik.Sitefinity.News.Model;
    using Telerik.Sitefinity.Web.DataResolving;
    using Telerik.Sitefinity.Pages.Model;
    using Telerik.Sitefinity.Modules.News.Web.UI;
     
     
    public partial class NewsTicker : System.Web.UI.UserControl
    {
        private int newsLimit = 5;
     
        public virtual int NewsLimit
        {
            get
            {
                return this.newsLimit;
            }
            set
            {
                this.newsLimit = value;
            }
        }
     
        protected void Page_Load(object sender, EventArgs e)
        {
            var totalItems = 0;
            var NewsList = from nl in App.WorkWith().NewsItems()
                           orderby nl.PublicationDate ascending
                           select nl;
            NewsList.Take(this.NewsLimit);
            NewsList.Count(out totalItems);
            this.RadRotator1.DataSource = NewsList.Get();
            this.RadRotator1.DataBind();
        }
    }
  2. Stanislav Velikov
    Stanislav Velikov avatar
    1113 posts
    Registered:
    18 Sep 2017
    19 Aug 2011
    Link to this post
    Hello Jingyuan,

    In the code behind you need to add additional logic because this link must point to a page that hosts a NewsView control, you should manually make query and get this page. In the following example the TargetNewsPage is represented by a read-only property:
    private PageNode targetNewsPage;
     
    protected PageNode TargetNewsPage
    {
        get
        {
            if (this.targetNewsPage == null)
            {
                this.targetNewsPage = App.WorkWith().Pages()
                            .Where(p => p.Page != null &&
                                        p.Page.Controls.Where(c => c.ObjectType.StartsWith(typeof(NewsView).FullName)).Count() > 0)
                            .Get().FirstOrDefault();
     
            } //it can still be null in case there is no page with a NewsView on it
     
            return this.targetNewsPage;
        }       
    }

    Refer to the complete example here.

    Best wishes,
    Stanislav Velikov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
2 posts, 0 answered