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

Forums / Developing with Sitefinity / Formatting dates on front end event items

Formatting dates on front end event items

11 posts, 0 answered
  1. TexKen
    TexKen avatar
    16 posts
    Registered:
    03 Mar 2006
    24 Jan 2011
    Link to this post
    I followed this article on how to override the embedded controls in sitefinity:
    http://www.sitefinity.com/devnet/kb/sitefinity-3-x/how-to-map-a-view-to-an-external-template-in-sitefinity-3-6-or-later.aspx

    This worked fine.  However, within the control template, I just get a bunch of literals.  What I want to do is format the event start and end dates differently, like instead of February 14, 2011 I want 2-14-2011.  I also want to show the time.

    Thanks,
    Craig
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    25 Jan 2011
    Link to this post
    Hello TexKen,

    The EventsView  control has an option inside its ControlDesigner >> Settings from where you can set the data format. This is also available for NewsView control.

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. TexKen
    TexKen avatar
    16 posts
    Registered:
    03 Mar 2006
    25 Jan 2011
    Link to this post
    Thanks for that Ivan.  However, I still can't see a way to show the time.  I can change the date to any format in the drop own list but there are no times.  This is odd because the admin allows you to set a time for the event. 

    any ideas?
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    25 Jan 2011
    Link to this post
    Hello TexKen,

    Try following suggestions provided in this post.

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. TexKen
    TexKen avatar
    16 posts
    Registered:
    03 Mar 2006
    25 Jan 2011
    Link to this post
    I tried that but it doesn't seem to see my new setting.  Below are the changes i made:

    <?xml version="1.0" encoding="utf-8" ?>
    <controlsConfig>
        <viewMap>
            <!-- Insert a new news item template -->
            <viewSettings hostType="Telerik.Events.WebControls.EventsView">
                <additionalTemplates>
                    <!--Item List-->
                    <add key="ItemListTemplate" layoutTemplatePath="~/CustomControls/Events/ContentViewItemView.ascx" />
                    <!--Single Item-->
                    <add key="SingleItemTemplate" layoutTemplatePath="~/CustomControls/Events/ContentViewSingleItemView.ascx" />
                </additionalTemplates>
            </viewSettings>
            <!--Events View Designer Template-->
            <viewSettings hostType="Telerik.Events.WebControls.Design.EventsViewDesigner" layoutTemplatePath="~/CustomControls/Events/EventsViewControlDesigner.ascx" />
        </viewMap>
    </controlsConfig>

    In EventsViewControlDesigner.ascx:

    <asp:Panel ID="dateTimeFormatPanel" runat="server">
        <asp:Label ID="lbl3" runat="server" Text="Date format" AssociatedControlID="dateTimeFieldFormat"></asp:Label>
        <asp:DropDownList ID="dateTimeFieldFormat" runat="server" >
            <asp:ListItem  Value="h:mm tt ddd, MMM d, yyyy" Text="h:mm tt ddd, MMM d, yyyy"  />
        </asp:DropDownList>
        <p class="example">Example</p>
    </asp:Panel>

    i've tried putting just MM-DD-YY and "Do Something" in the text property but no effect. 
  6. TexKen
    TexKen avatar
    16 posts
    Registered:
    03 Mar 2006
    26 Jan 2011
    Link to this post
    bump!
  7. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    01 Feb 2011
    Link to this post
    Hello TexKen,

    I do not see what the problem would be here, since this seems to work fine at my end. What you can try is adding the code below to the templates where you want to predefine the date format.

    • ContentViewItemView.ascx
    • ContentViewSingleItemView.ascx
    <script type="text/C#"runat="server">
       
         
       
         public voidPage_Load(objectsender, EventArgs e)
       
         {
       
             this.repeater.ItemDataBound += new RepeaterItemEventHandler(repeater_ItemDataBound);
       
         }
       
        
       
         void repeater_ItemDataBound(objectsender, RepeaterItemEventArgs e)
       
         {
       
             if(e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
       
             {
       
                 var cntrl = (Literal)e.Item.FindControl("Event_End");
       
                 if(cntrl != null)
       
                 {
       
                     var content = (Telerik.Cms.Engine.IContent)e.Item.DataItem;
       
                     if(content != null)
       
                     {
       
                      var date = (DateTime)content.GetMetaData("Event_Start");
       
                      var ds = date.ToString("h:mm tt ddd");
      
       
                     }
       
                 }
       
             }
       
         }  
       
             
       
    </script>

    You can assign the value above to a ITextControl that you can add to the template. The code above will allow you to see the exact format that is returned by date.ToString

    Also you can check the values of the metafields that are stored in the database for Application = '/Events'. This could be done in sf_GCMetaData table.
    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  8. TexKen
    TexKen avatar
    16 posts
    Registered:
    03 Mar 2006
    02 Feb 2011
    Link to this post
    I'm trying to do this on the ContentViewSingleItemView.ascx but there is no repeater on that page and i get compile errors.  Is there some other control you are databinding against?
  9. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    02 Feb 2011
    Link to this post
    Hello TexKen,

    Yes, there is no repeater. You can access the data item - IContent from the HtpContext and the the metadata from there

    var Manager = new EventsManager("Events");
    itemId = (Guid)((IUrlRewriteData)Context.Items[Manager.Provider.ContentItemKey]).Data;

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  10. Scott Rozman
    Scott Rozman avatar
    93 posts
    Registered:
    10 Oct 2012
    22 Feb 2011
    Link to this post
    TexKen-
    I was just running into the same issue. My date formatting seems to be working fine within News, but is not working on my events control.

    I noticed that on my modified ContentViewItemView.ascx external template, there was

    <telerik:DateTimeLiteral runat="server" ID="Event_Start" DateFormatString="D"></telerik:DateTimeLiteral>

    Looking at the original un-modified version of that template, there was

    <telerik:DateTimeLiteral runat="server" ID="Publication_Date" DateFormatString="D"></telerik:DateTimeLiteral>

    I changed the DateFormatString to my preferred one:
    <telerik:DateTimeLiteral runat="server" ID="Event_Start" DateFormatString="h:mm tt ddd, MMM d, yyyy"></telerik:DateTimeLiteral>

    and the dates on the item listing and single item are now all displaying the way I want.

    The original problem would have made more sense, if the format settings were making no effect on the page, but if I happened to chose "Tuesday" or "Tues, Feb 22", I was getting a yellow screen with

    String was not recognized as a valid DateTime because the day of week was incorrect.


    I also just did a test removing the DateFormatString from the external template, but then it defaults to
    2/21/2011 12:00:00 PM even when I pick something different on the backend.
  11. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    25 Feb 2011
    Link to this post
    Hi Scott,

    The problem is that there is no Time picker for Publication_Date and Expiration_Date and this is why you see only 12:00 You can use Event_Start and Event_End which values are correctly shown.

    sample code that will allow you to see the proper format of the date in events list

    script type="text/C#"runat="server">
       
         
       
         public void Page_Load(objectsender, EventArgs e)
       
         {
       
             this.repeater.ItemDataBound += new RepeaterItemEventHandler(repeater_ItemDataBound);
       
         }
       
        
       
         void repeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
       
         {
       
             if(e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
       
             {
       
                 var cntrl = (Literal)e.Item.FindControl("Event_End");
       
                 if(cntrl != null)
       
                 {
       
                     var content = (Telerik.Cms.Engine.IContent)e.Item.DataItem;
       
                     if(content != null)
       
                     {
       
                      var date = (DateTime)content.GetMetaData("Event_Start");
       
                      var ds = date.ToString("M.d.yyyy h:mm tt");
       
                      cntrl.Text = ds;
       
                     }
       
                 }
       
             }
       
         
       
             
       
    </script>


    All the best,
    Ivan Dimitrov
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Register for webinar
11 posts, 0 answered