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

Forums / Developing with Sitefinity / NewsCalendar customizing help

NewsCalendar customizing help

11 posts, 0 answered
  1. Jules
    Jules avatar
    65 posts
    Registered:
    20 Jul 2005
    13 Dec 2007
    Link to this post
    I'm trying to take the NewsCalendar control from the TIU sample site and integrate it into a project. I've made a few minor edits to get it into my site, but I'm having a little trouble figuring out if/how to do this last thing.

    We're trying to use it as an events calendar. I want to be able to show the news items with publication dates that are equal to today or in the future.

    Any suggestions are welcome, as I'm trying to get this in place for a go-live tomorrow!

    Thanks,
    Jules
  2. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    14 Dec 2007
    Link to this post
    Hi Julia Essex,

    You can use the FilterExpression property to filter news items in the list by Publication_Date.Generate the filter expression programmatically and set the value to FilterExpression property. For example:

    ContentManager manager = new ContentManager("News"); 
    DateTime date = DateTime.Now; 
    manager.FilterExpression = "Publication_Date >= " + date.ToShortDateString(); 
    IList list = manager.GetContent(); 
     
    newsList.CustomDataSource = list; 
    newsList.DataBind(); 
     

    Hope this is helpful.

    All the best,
    Pepi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. Jules
    Jules avatar
    65 posts
    Registered:
    20 Jul 2005
    19 Dec 2007
    Link to this post
    Thanks!

    Ok, next part. I've got it set to show all the current/future items as special days, and have filtered the newslist control's items to match. Next I need to add in filtering for the category. So.... I'm running into a hitch.

    In populating the newslist I use the following code:
    ContentManager manager = new ContentManager("News"); 
                DateTime date = DateTime.Today; 
                manager.FilterExpression = "Publication_Date >= " + date.ToShortDateString(); 

    I tried altering this so the filterexpression read as follows:
    manager.FilterExpression = "Publication_Date >= " + date.ToShortDateString() + " AND Category ~ 'Calendar of Events'"

    (and I've tried with Category =), but all that happens is the entire filter seems to be ignored.

    For the list of specialdays on the calendar, my current code (without filtering) is as follows:
    NewsManager manager = new NewsManager(NewsManager.DefaultContentProvider); 
             
            List<IMetaSearchInfo> filter = new List<IMetaSearchInfo>(); 
             
            filter.Add(new MetaSearchInfo(MetaValueTypes.DateTime, 
                            this.newsList.PublicationDateField, DateTime.Today, SearchCondition.GreaterOrEqual)); 
             
            IList source = manager.Content.GetContent(0, int.MaxValue, "", ContentStatus.Published, filter.ToArray()); 
     Honestly I have no clue how to alter this one. I could write the filter on the shorttext metavalue type, but to what field?

    If there's an easier way than the ways I've tried, please point it out. I know I'm missing something here, but I just can't quite figure out what.

    thanks,
    Jules
  4. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    20 Dec 2007
    Link to this post
    Hi Julia Essex,

    Try to change the FilterExpression as follows:

    manager.FilterExpression = "Publication_Date >= " + date.ToShortDateString() + " ; Category ~ 'Calendar of Events'"

    i.e. you need to replace AND with ; (semi-colon).

    Hope this helps.

    Best wishes,
    Pepi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  5. Jules
    Jules avatar
    65 posts
    Registered:
    20 Jul 2005
    09 Jan 2008
    Link to this post
    I am still struggling with this. I used the code you gave me and the category filtering is now working brilliantly for the calendar's SpecialDays, BUT I am at a loss as to how to control the newsList.

    Here's what I have now for the newsList in the ascx file:
    <sfNews:NewsList EnableViewState="false" runat="server" ID="newsList" NewsCount="100" 
        PagingMode="NextPrev" AllowPaging="true" SelectMode="All" NewsItemsPerPage="2" 
        ShowNewsTags="false" CssClass="NewsCalendar" SingleNewsPage="~/Home/CalendarEvent.aspx"  
        PublicationDateField="Publication_Date" SortBy="Publication_Date ASC"
    </sfNews:NewsList> 

    and here is the control's code-behind:

    1using System; 
    2using System.Data; 
    3using System.Configuration; 
    4using System.Collections; 
    5using System.Web; 
    6using System.Web.Security; 
    7using System.Web.UI; 
    8using System.Web.UI.WebControls; 
    9using System.Web.UI.WebControls.WebParts; 
    10using System.Web.UI.HtmlControls; 
    11using System.Data.SqlClient; 
    12using Telerik.WebControls; 
    13using Telerik.News; 
    14using System.Drawing; 
    15using Telerik.Cms.Engine; 
    16using System.Web.UI.MobileControls; 
    17using Telerik.Cms.Engine.Data; 
    18using Telerik.News.WebControls; 
    19using System.Collections.Generic; 
    20using System.ComponentModel; 
    21using Telerik.Cms.Web.UI; 
    22 
    23public partial class MyControls_NewsCalendar : System.Web.UI.UserControl 
    24
    25 
    26    public NewsList NewsList 
    27    { 
    28        get 
    29        { 
    30            return this.newsList; 
    31        } 
    32        set 
    33        { 
    34            this.newsList = value; 
    35        } 
    36    } 
    37     
    38    protected override void OnInit(EventArgs e) 
    39    { 
    40        this.RadCalendar1.SelectionChanged += new Telerik.WebControls.Base.Calendar.Events.SelectedDatesEventHandler(RadCalendar1_SelectionChanged); 
    41        this.RadCalendar1.DefaultViewChanged += new Telerik.WebControls.Base.Calendar.Events.DefaultViewChangedEventHandler(RadCalendar1_DefaultViewChanged); 
    42        base.OnInit(e); 
    43    } 
    44 
    45    void RadCalendar1_DefaultViewChanged(object sender, Telerik.WebControls.Base.Calendar.Events.DefaultViewChangedEventArgs e) 
    46    { 
    47        this.CalculateDays(); 
    48    } 
    49 
    50    void RadCalendar1_SelectionChanged(object sender, Telerik.WebControls.Base.Calendar.Events.SelectedDatesEventArgs e) 
    51    { 
    52        this.newsList.SelectMode = NewsList.SelectModes.SingleDate; 
    53        this.newsList.NewsCount = 0; 
    54        this.newsList.SelectedDate = this.RadCalendar1.SelectedDate; 
    55    } 
    56 
    57    protected void Page_Load(object sender, EventArgs e) 
    58    { 
    59        if (!Page.IsPostBack) 
    60        { 
    61            ContentManager manager = new ContentManager("News"); 
    62            DateTime date = DateTime.Today; 
    63            manager.FilterExpression = "Publication_Date >= " + date.ToShortDateString() + " ; Category ~ 'Calendar of Events'"
    64 
    65            IList list = manager.GetContent(); 
    66 
    67            newsList.CustomDataSource = list; 
    68            newsList.DataBind(); 
    69 
    70            this.CalculateDays(); 
    71        } 
    72    } 
    73 
    74    protected void CalculateDays() 
    75    { 
    76        ContentManager manager = new ContentManager("News"); 
    77        DateTime mydate = DateTime.Today; 
    78        manager.FilterExpression = "Publication_Date >= " + mydate.ToShortDateString() + " ; Category ~ 'Calendar of Events'"
    79 
    80        IList source = manager.GetContent(); 
    81 
    82        int month = RadCalendar1.FocusedDate.Month; //DateTime.Now.Month; 
    83        int year = RadCalendar1.FocusedDate.Year; //DateTime.Now.Year; 
    84        foreach (IContent data in source) 
    85        { 
    86            DateTime date = (DateTime)data.GetMetaData("Publication_Date"); 
    87            if (date.Month == month && date.Year == year) 
    88                this.AddSpecialDay(date); 
    89        } 
    90    } 
    91 
    92    protected void AddSpecialDay(DateTime date) 
    93    { 
    94        RadCalendarDay day = new RadCalendarDay(); 
    95        day.Date = date; 
    96        day.IsSelectable = true
    97        day.ItemStyle.CssClass = "radCalSpecialDay_Global"
    98        day.Repeatable = Telerik.WebControls.Base.Calendar.Enumerations.RecurringEvents.DayAndMonth; 
    99        day.ToolTip = "Click for the news and events of the day"
    100 
    101        RadCalendar1.SpecialDays.Add(day); 
    102    } 
    103 
    104    protected override void OnPreRender(EventArgs e) 
    105    { 
    106        base.OnPreRender(e); 
    107 
    108        string datesArray = "var dates = new Array("
    109        for (int i = 0; i < RadCalendar1.SpecialDays.Count; i++) 
    110        { 
    111            RadCalendarDay day = RadCalendar1.SpecialDays[i]; 
    112            datesArray += "[" + day.Date.Year + ", " + day.Date.Month + ", " + day.Date.Day + "]"
    113            if (i < RadCalendar1.SpecialDays.Count - 1) 
    114                datesArray += ","
    115        } 
    116        datesArray += ");"
    117 
    118        this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "datesArray", datesArray, true); 
    119    } 
    120
    121 


    We've had to go ahead and release the site without the control, and I've promised to implement the control as soon as I can. The two things I have left are 1) ordering the newsList in ascending order starting with today, and 2) filtering the newsList to only include items of the category "Calendar of Events".

    I thought the code I have should filter the contents of the newsList by the category, but I suspect somehow it's being overridden. Any ideas? I've tried just putting the category filter in the ascx file, i.e. SelectedCategories="Calendar of Events", but that throws an exception. As you can see, I've put the sort information in there but it's having no effect whatsoever on the output -- the output list appears to be random, but I suspect it's in the order the entries were created rather than the order of publication.

    Thanks in advance for any help y'all can offer!

    jules
  6. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    09 Jan 2008
    Link to this post
    Hi Julia,

    There are a few things that are not quite clear. First of all what is the idea of the RadCalendar in your UserControl as you want to display only the news items with a publication date that is equal to today or greater than today. In fact you don't need a calendar to achieve this. Are you using the RadCalendar to filter the items?

    Regarding your question about sorting news items by Publication_Date in ascending order, try to use ContentManager.GetContent(string sortExpr) method instead of ContentManager.GetContent() method.  For example:

    ... 
    IList source = manager.GetContent("Publication_Date ASC"); 
    ... 

    As for filtering by Category, it seems to work according to expectations. I would recommend you simplify the implementation and remove the unnecessary code. For example, if we accept that you don't need the calendar for filtering the news items, Page_Load can be simplified as follows:

        protected void Page_Load(object sender, EventArgs e)  
        {  
            if (!Page.IsPostBack)  
                this.CalculateDays();  
        }  
      
        protected void CalculateDays()  
        {  
            ContentManager manager = new ContentManager("News");  
            DateTime mydate = DateTime.Today; 
            manager.FilterExpression = "Publication_Date >= " + mydate.ToShortDateString() + " ; Category ~ 'Calendar of Events'"
     
            IList source = manager.GetContent("Publication_Date ASC"); 
     
            newsList.CustomDataSource = source; 
            newsList.DataBind();  
        } 

    Let us know how it goes.

    Sincerely yours,
    Pepi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  7. Jacques
    Jacques avatar
    427 posts
    Registered:
    28 Jun 2007
    11 Nov 2009
    Link to this post
    Hi Pepi,

    I have a similar situation, but we're using the RadRotator to flip through News Items. I have the following code:

    DateTime filterDate = new DateTime(DateTime.Now.Year - 1, 1, 1); 
    _NewsManager.Content.FilterExpression = "Publication_Date >= " + filterDate.ToShortDateString(); 
     
    RadRotator1.DataSource = _NewsManager.Content.GetContent("Publication_Date DESC"); 
    RadRotator1.ItemDataBound += new RadRotatorEventHandler(RadRotator1_ItemDataBound); 
    RadRotator1.DataBind(); 

    We definitely have articles for dates past the given year, but the data bind is coming up with no articles.

    Will your code example work for the NewsManager as it does with the ContentManager?

    Regards,
    Jacques
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    11 Nov 2009
    Link to this post
    Hello J.Hov,

    The News module is based on Generic Content. All methods used by NewsManager are actually methods of the ContentManager class.

    All the best,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  9. Jacques
    Jacques avatar
    427 posts
    Registered:
    28 Jun 2007
    11 Nov 2009
    Link to this post
    Hi Ivan,

    Based on the code I provided then, why would we see no results? 

    Regards,
    Jacques
  10. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    11 Nov 2009
    Link to this post
    Hi J.Hov,

    You can attach the code ItemDataBound event of the Radrotator control and see what is going wrong. Also you are applying a filter to the control that could hide the items. Also it will be better first to get a list of content items and filter this list using ContentFilterbuilder or IMetaSearchInfo classes.

    Regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  11. Jacques
    Jacques avatar
    427 posts
    Registered:
    28 Jun 2007
    11 Nov 2009
    Link to this post
    Wow, that didn't make much sense at all. 

    You can attach the code ItemDataBound event of the Radrotator control and see what is going wrong. Also you are applying a filter to the control that could hide the items. Also it will be better first to get a list of content items and filter this list using ContentFilterbuilder or IMetaSearchInfo classes.

    1. We're already attached to the ItemDataBound event which is where we're dynamically setting up each news item (text, image, date, etc.) And that works perfectly fine when there's no filter applied. And it works with sorting. 
    2. Can you be a bit more specific in terms of "See what's going wrong"? That's why I posted on your site is to hopefully get a clue from you guys as to 'what' to look for. 
    3. No we're only applying a filter where I indicated in the code that I attached in my previous post. 
    4. "Also it will be better first to get a list of content items and filter this list using ContentFilterbuilder or IMetaSearchInfo classes." What? 

    Were you in a rush when you replied? If so, I'll gladly wait till someone else answers. 

    Regards,
    Jacques

Register for webinar
11 posts, 0 answered