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

Forums / Developing with Sitefinity / EventsView Control

EventsView Control

3 posts, 0 answered
  1. Cameron
    Cameron avatar
    42 posts
    Registered:
    27 Jul 2009
    15 Jul 2011
    Link to this post
    Hi... I am working with the EventsView control to display a list of events. I am trying to access the Event_End data field and only display it if it is different from the Event_Start data field. I know I can change many of the looks of the output by editing the ContentViewItemView.asc file but because the Event_End isn't directly addressed in that page I can't get to it.

    I then copied the EventsViewCustomControl that was talked about in the forums (http://www.sitefinity.com/devnet/forums/sitefinity-3-x/developing-with-sitefinity/adding-provinces-to-the-event-module.aspx) and I'm now using that control and a custom ContentViewItemView.asc template. From the control it looks like the Event_End data is assigned to the "ed" variable.

    I think I'm lost when it comes to  actually using that "ed" on the page to run a conditional statement against. I've tried all the variations of this.FindControl() I could think of, but no luck.

    Can you give me any tips on how I can use this to run a simple if...then using the Event_End date?

    Thanks!
  2. Cameron
    Cameron avatar
    42 posts
    Registered:
    27 Jul 2009
    21 Jul 2011
    Link to this post
    Thanks to Telerik support and some more digging, here's what worked if anyone is interested:

    On the .ascx control display page, include:

    <asp:Literal ID="EndDateLit" runat="server" EnableViewState="true" />

    On the back-end .cs control page:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Telerik.Events.WebControls;
    using Telerik.Cms.Engine.ContentViewFiltering;
    using Telerik.Cms.Engine;
    using System.Web.UI;
    using System.Web.UI.WebControls;
     
    /// <summary>
    /// Summary description for EventsViewCustomControl
    /// </summary>
    public class EventsViewCustomControl : EventsView
    {
        public EventsViewCustomControl()
        {
        }
    protected override void SetItemMetadata(Control itemContainer, IContent contentItem)
        {
            DateTime pd = (DateTime)contentItem.GetMetaData("Event_Start");
            DateTime ed = (DateTime)contentItem.GetMetaData("Event_End");
            Literal EndDateLit = FindContentViewControl("EndDateLit", itemContainer) as Literal;
        
            if (pd.Date != ed.Date)
            {
                EndDateLit.Text = " - " + String.Format("{0:MMMM d, yyyy}", ed);
            }
     
            base.SetItemMetadata(itemContainer, contentItem);
        }
     
        protected override void SetSingleItemContent(IContent item)
        {
            base.SetSingleItemContent(item);
        }
     
    }
  3. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    26 Jul 2011
    Link to this post
    Hello Michael Buchsbaum,

    I have attached a sample control that I am using. I am using external templates to make sure that the literal in question exists. Please make sure that you have events whose start and end dates fall in the if statement.


    All the best,
    Radoslav Georgiev
    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
Register for webinar
3 posts, 0 answered