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

Forums / Developing with Sitefinity / Event Schedule View as Calendar

Event Schedule View as Calendar

18 posts, 0 answered
  1. Paul
    Paul avatar
    176 posts
    Registered:
    18 Nov 2008
    17 Apr 2009
    Link to this post

    Hi!

    I have read a lot information about Event Schedule View control but  I never found information about showing this control as compact calendar with selected days where we have events. What can you suggest me to use in this case? 

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    17 Apr 2009
    Link to this post
    Hi Paul,

    You could find the following post useful - Using your own Master Page and providing blog-like calendar navigation. As the blogs and events are content items the situation is similar. The popup calendar in RadScheduler is RadCalendar and it is a child control of RadScheduler. The RadCalendar ID is "SelectedDateCalendar", so getting a reference can be done in RadScheduler's PreRender event.

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Paul
    Paul avatar
    176 posts
    Registered:
    18 Nov 2008
    17 Apr 2009
    Link to this post

    Thanks for the link. But I have problems with that sample for example problem with assembly Telerik.WebControls.dll. I can't find It.

    Can you also describe more clearly the second part of your post about PreRender event and SelectedDateCalendar.

  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    17 Apr 2009
    Link to this post
    Hello Paul,

    Currently all Rad controls are in Telerik.Web.UI assemble. We have our controls - as NewsView, EventsView that are build in our assembles - Telerik.News.dll and Telerik.Events.dll
    The build in calendar can be accessed using Scheduler_PreRender method amd recursion.

    Example:

     
    protected void RadScheduler1_PreRender(object sender, EventArgs e) 
       RadCalendar calendar= RadScheduler1.FindControl("SelectedDateCalendar"as RadCalendar; 


    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  5. Paul
    Paul avatar
    176 posts
    Registered:
    18 Nov 2008
    17 Apr 2009
    Link to this post
    Can you write a full example on how work with RadCalendar and Events? I will be very appreciated. 
  6. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    21 Apr 2009
    Link to this post
    Hello Paul,

    The other thing you could do, is the following:
    1. Create a User control with a calendar. This could be a RadCalendar for example
    2. Get all events using Telerik.Events.EventsManager.GetEvents. You will have an IList with events which may serve you as a datasource.
    3. Create a List with items that can be bound to the Calendar.

    As for the samples, we will try to provide a similar sample in our blogs in form of an article. I cannot commit to a time frame though.

    Regards,
    Georgi
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  7. Paul
    Paul avatar
    176 posts
    Registered:
    18 Nov 2008
    21 Apr 2009
    Link to this post

    Hi Georgi!

    Thank you for your suggestion! I will try It. And also I will be waiting a great article on this thing in your blogs.

  8. Paul
    Paul avatar
    176 posts
    Registered:
    18 Nov 2008
    21 Apr 2009
    Link to this post
    Finally I create my control with radcalendar which contains my events. But now I have another problem. I get error: "Template with ID: 04.21.2009 not found.". I have read this thread on telerik forum(http://www.telerik.com/community/forums/aspnet/calendar/code-behind-way-of-doing-special-days.aspx) but I don't understand what I should do. Can you explain more clearly a part with IsPostBack event and template of redcalendar?
  9. Chanan Zass
    Chanan Zass avatar
    123 posts
    Registered:
    21 Aug 2012
  10. Paul
    Paul avatar
    176 posts
    Registered:
    18 Nov 2008
    23 Apr 2009
    Link to this post

    Hi Chanan!

    Can you send me your version of calendar for events? 

    Thanks for the link.

  11. Chanan Zass
    Chanan Zass avatar
    123 posts
    Registered:
    21 Aug 2012
    23 Apr 2009
    Link to this post

    Here it is (VB.NET).
    I should note that I'm using a dataset instead of using the Events provider (Telerik.Events.EventsManager.GetEvents). Wrong thing to do, but I'm still behind on learning how to use these things.

    It would be a good idea, then, to replace my dataset with an iList of all events. Will do it myself whenever I have a minute.

    EventsCalendar.ascx

    <%@ Control Language="VB" AutoEventWireup="false" CodeFile="EventsCalendar.ascx.vb" Inherits="UserControls_EventsCalendar" %> 
     
        <div> 
       
            <telerik:RadCalendar ID="RadCalendar1" Runat="server" EnableMultiSelect="False"   
                font-names="Arial,Verdana,Tahoma" forecolor="Black" SelectedDate=""   
                style="border-color: #ececec" ViewSelectorText="x"   
                OnSelectionChanged="cmdSelectionChanged" CultureInfo="Italian (Italy)"   
                Skin="Forest" Width="210px" TitleFormat="MMMM yyyy" AutoPostBack="True"   
                ShowRowHeaders="False" UseRowHeadersAsSelectors="False"   
                ShowOtherMonthsDays="False" OnDayRender="cmdDayRender">  
                <CalendarDayTemplates> 
                    <telerik:DayTemplate ID="dayTemplate1">  
                        <Content> 
                            <asp:HyperLink ID="lnkEvent" runat="server" Text="99" NavigateUrl="http://www.endormedia.com/Events.aspx" Font-Bold="true" /> 
                        </Content> 
                    </telerik:DayTemplate> 
                    </CalendarDayTemplates> 
     
            </telerik:RadCalendar> 
        </div> 
          
     

    EventsCalendar.ascx.vb
    Imports System.Data  
    Imports Telerik.Web.UI  
    Imports System.Data.SqlClient  
     
    Partial Class UserControls_EventsCalendar  
       Inherits System.Web.UI.UserControl  
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load  
     
            BindCalData()  
     
        End Sub  
        Protected Sub BindCalData()  
            Dim strResult As String = "" 
            If Not IsPostBack Then  
                Dim ds As DataSet = GetEvents()  
                ' You may use instead a different data source (Telerik.Events.EventsManager.GetEvents) to get an iList  
                ' but I still have to learn how one uses that, so I just use an old-style dataset which I cache for 5 minutes  
                If ds.Tables(0).Rows.Count > 0 Then  
                    Dim calDate As DateTime = Nothing 
                    Dim evTitle As String = "" 
     
                    ' read data from events dataset and assign to cells  
                    Dim int As Integer = 1 
                    For Each row As DataRow In ds.Tables(0).Rows  
                        If IsDBNull(row("Start")) = False Then  
                            calDate = CDate(row("Start"))  
                            evTitle = row("Title")  
                            Dim NewDay As New RadCalendarDay(RadCalendar1)  
                            NewDay.[Date] = New DateTime(calDate.Year, calDate.Month, calDate.Day)  
                            NewDay.Repeatable = Calendar.RecurringEvents.None  
     
                            NewDay.TemplateID = "dayTemplate1" 
                            NewDay.ToolTip = evTitle 
                            NewDay.ItemStyle.BackColor = Drawing.Color.AliceBlue  
                            NewDay.ItemStyle.BorderStyle = BorderStyle.Solid  
                            NewDay.ItemStyle.BorderWidth = 1 
                            NewDay.ItemStyle.BorderColor = Drawing.Color.Blue  
                            RadCalendar1.SpecialDays.Add(NewDay)  
                            intint = int + 1  
                        End If  
     
                    Next  
     
                End If  
                ds.Dispose()  
     
            End If  
     
        End Sub  
        Protected Sub cmdSelectionChanged(ByVal sender As Object, ByVal e As Telerik.Web.UI.Calendar.SelectedDatesEventArgs) Handles RadCalendar1.SelectionChanged  
            ' BindCalData()  
     
        End Sub  
     
        Protected Sub cmdDayRender(ByVal sender As Object, ByVal e As Telerik.Web.UI.Calendar.DayRenderEventArgs) Handles RadCalendar1.DayRender  
            Dim renderedDay As String = e.Day.Date.AddDays(1).Day.ToString  
            Dim myTemplate As DayTemplate  
            myTemplate = RadCalendar1.CalendarDayTemplates.Item("dayTemplate1")  
            Dim pubDate As String = "" 
            Dim titleUrl As String = "" 
     
            If Not myTemplate Is Nothing Then  
                Dim ds As DataSet  
                ds = GetEvents()  
     
                Dim myLink As HyperLink = Nothing 
                For Each ctr As Control In RadCalendar1.Controls  
                    myLink = DirectCast(ctr.FindControl("lnkEvent"), HyperLink)  
                    If Not myLink Is Nothing Then  
                        If ds.Tables(0).Rows.Count > 0 Then  
                            For Each row As DataRow In ds.Tables(0).Rows  
                                If CDate(row("Start")).Date.ToShortDateString = e.Day.Date.AddDays(1).ToShortDateString Then  
                                    pubDate = CDate(row("Publication_Date")).Date.Year.ToString & "-" & CDate(row("Publication_Date")).Date.Month.ToString("D2") & "-" & CDate(row("Publication_Date")).Date.AddDays(1).Day.ToString("D2")  
                                    If pubDate.Length > 0 Then  
                                        pubDate = Mid(pubDate, 3)  
                                    End If  
                                    titleUrl = row("Title")  
     
                                    titleUrl = Replace(Replace(titleUrl, "'", "_"), "’", "_")  
                                    titleUrl = Replace(titleUrl, " ", "_")  
                                    titleUrl = Replace(titleUrl, "__", "_")  
                                    titleUrl = System.Text.RegularExpressions.Regex.Replace(titleUrl, "[^\w\.-]", "")  
                                    Exit For  
                                End If  
                            Next  
                        End If  
     
     
                        myLink.Text = renderedDay 
                        myLink.NavigateUrl = "~/it/eventi/" & pubDate & "/" & titleUrl & ".aspx?Events=EventItem"  
                    End If  
                Next  
                ds.Dispose()  
     
            End If  
        End Sub  
     
        Function GetEvents() As DataSet  
            Dim text1 As String = ("EventsDataSet")  
            Dim ds As New DataSet  
            If (HttpContext.Current.Cache.Item(text1) Is Nothing) Then  
                Dim app As String = "/Events" 
                Dim lang As Integer = 127 
                Dim sqlst As String = "SELECT ev.[ID], ev.[ContentID], ev.[Start], ev.[End], mt.ShortText As Title, (SELECT md.DateTimeValue FROM sf_GCMetaData md WHERE md.ContentID = ev.ContentID And md.LangId = " & lang.ToString & " And md.KeyValue = 'Publication_Date' And md.Status = 1 And md.Application = '" & app & "') As Publication_Date FROM sf_Events ev INNER JOIN sf_GCMetaData mt ON mt.ContentID = ev.ContentID And mt.LangId = " & lang.ToString & " And mt.KeyValue = 'Title' And mt.Status = 1 And mt.Application = '" & app & "' And ev.Start >= getDate();"  
     
                Dim myConnection As New SqlConnection(ConfigurationManager.ConnectionStrings("Sitefinity").ToString)  
                Dim adapter1 As New SqlDataAdapter(sqlst, myConnection)  
     
                adapter1.Fill(ds)  
                ' Insert ds in cache for 5 minutes  
                HttpContext.Current.Cache.Insert(text1, ds, Nothing, DateTime.Now.AddMinutes(5.0), TimeSpan.Zero)  
                adapter1.Dispose()  
                If myConnection.State = ConnectionState.Open Then  
                    myConnection.Close()  
                End If  
            End If  
            Return CType(HttpContext.Current.Cache.Item(text1), DataSet)  
            ' Return ds  
     
        End Function  
    End Class  
     

  12. Chanan Zass
    Chanan Zass avatar
    123 posts
    Registered:
    21 Aug 2012
    23 Apr 2009
    Link to this post
    Okay, delved into the Developer Manual and replaced the dataset with iList:

    EventsCalendar.ascx.vb:
    Imports System.Data  
    Imports Telerik.Web.UI  
    Imports System.Data.SqlClient  
     
    Partial Class UserControls_EventsCalendar  
       Inherits System.Web.UI.UserControl  
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load  
     
            BindCalData()  
     
        End Sub  
        Protected Sub BindCalData()  
            Dim strResult As String = "" 
            If Not IsPostBack Then  
                Dim eventManager As New Telerik.Events.EventsManager("Events")  
                Dim fromDate As New DateTime  
                fromDate = Today.AddDays(-1).Date  
                Dim toDate As New DateTime  
                toDAte = Today.AddYears(100).Date  
                ' get all events starting yesterday and sorted by startDate  
                Dim listOfEvents As IList = eventManager.GetEvents(fromDate, toDate, "[Start] ASC")  
     
                If (listOfEvents.Count > 0) Then  
                    Dim calDate As DateTime = Nothing 
                    Dim evTitle As String = "" 
     
                    ' read data and assign to cells  
                    Dim int As Integer = 1 
                    For Each eventItem As Telerik.Events.IEvent In listOfEvents  
                        If IsDBNull(eventItem.Start) = False Then  
                            calDate = CDate(eventItem.Start)  
                            evTitle = eventItem.EventTitle  
                            Dim NewDay As New RadCalendarDay(RadCalendar1)  
                            NewDay.[Date] = New DateTime(calDate.Year, calDate.Month, calDate.Day)  
                            NewDay.Repeatable = Calendar.RecurringEvents.None  
     
                            NewDay.TemplateID = "dayTemplate1" 
                            NewDay.ToolTip = evTitle 
                            NewDay.ItemStyle.BackColor = Drawing.Color.AliceBlue  
                            NewDay.ItemStyle.BorderStyle = BorderStyle.Solid  
                            NewDay.ItemStyle.BorderWidth = 1 
                            NewDay.ItemStyle.BorderColor = Drawing.Color.Blue  
                            RadCalendar1.SpecialDays.Add(NewDay)  
                            intint = int + 1  
                        End If  
     
                    Next  
     
                End If  
            End If  
     
        End Sub  
        Protected Sub cmdSelectionChanged(ByVal sender As Object, ByVal e As Telerik.Web.UI.Calendar.SelectedDatesEventArgs) Handles RadCalendar1.SelectionChanged  
            ' BindCalData()  
     
        End Sub  
     
        Protected Sub cmdDayRender(ByVal sender As Object, ByVal e As Telerik.Web.UI.Calendar.DayRenderEventArgs) Handles RadCalendar1.DayRender  
            Dim renderedDay As String = e.Day.Date.AddDays(1).Day.ToString  
            Dim myTemplate As DayTemplate  
            myTemplate = RadCalendar1.CalendarDayTemplates.Item("dayTemplate1")  
            Dim pubDate As String = "" 
            Dim titleUrl As String = "" 
     
            If Not myTemplate Is Nothing Then  
                Dim eventManager As New Telerik.Events.EventsManager("Events")  
                Dim fromDate As New DateTime  
                fromDate = Today.AddDays(-1).Date  
                Dim toDate As New DateTime  
                toDate = Today.AddYears(100).Date  
                ' get all events starting yesterday and sorted by startDate  
                Dim listOfEvents As IList = eventManager.GetEvents(fromDate, toDate, "[Start] ASC")  
     
                Dim myLink As HyperLink = Nothing 
                For Each ctr As Control In RadCalendar1.Controls  
                    myLink = DirectCast(ctr.FindControl("lnkEvent"), HyperLink)  
                    If Not myLink Is Nothing Then  
                        If (listOfEvents.Count > 0) Then  
                            For Each eventItem As Telerik.Events.IEvent In listOfEvents  
                                If CDate(eventItem.Start).Date.ToShortDateString = e.Day.Date.AddDays(1).ToShortDateString Then  
                                    pubDate = CDate(eventItem.ContentItem.DateCreated).Date.Year.ToString & "-" & CDate(eventItem.ContentItem.DateCreated).Date.Month.ToString("D2") & "-" & CDate(eventItem.ContentItem.DateCreated).Date.Day.ToString("D2")  
                                    If pubDate.Length > 0 Then  
                                        pubDate = Mid(pubDate, 3)  
                                    End If  
     
                                    titleUrl = eventItem.EventTitle  
     
                                    titleUrl = Replace(Replace(titleUrl, "'", "_"), "’", "_")  
                                    titleUrl = Replace(titleUrl, " ", "_")  
                                    titleUrl = Replace(titleUrl, "__", "_")  
                                    titleUrl = System.Text.RegularExpressions.Regex.Replace(titleUrl, "[^\w\.-]", "")  
                                    Exit For  
                                End If  
                            Next  
                        End If  
     
     
                        myLink.Text = renderedDay 
                        myLink.NavigateUrl = "~/it/eventi/" & pubDate & "/" & titleUrl & ".aspx?Events=EventItem"  
                    End If  
                Next  
     
            End If  
        End Sub  
    End Class  
     
  13. Chanan Zass
    Chanan Zass avatar
    123 posts
    Registered:
    21 Aug 2012
    23 Apr 2009
    Link to this post
    Last thing:
    In the master page I've inserted:
    <asp:ScriptManager ID="ScriptManager1" runat="server">  
            </asp:ScriptManager> 
         <telerik:radajaxmanager id="RadAjaxManager1" runat="server">  
            <AjaxSettings> 
                <telerik:AjaxSetting AjaxControlID="RadCalendar1">  
                    <UpdatedControls> 
                        <telerik:AjaxUpdatedControl ControlID="RadCalendar1"></telerik:AjaxUpdatedControl> 
                    </UpdatedControls> 
                </telerik:AjaxSetting> 
            </AjaxSettings> 
        </telerik:radajaxmanager> 

    so the page does not reload on each view change.
  14. Paul
    Paul avatar
    176 posts
    Registered:
    18 Nov 2008
    25 Apr 2009
    Link to this post

    Hi Chanan!

    Thank you for your code very much! I fixed all my problems with RadCalendar and now It works great. 

  15. Paul
    Paul avatar
    176 posts
    Registered:
    18 Nov 2008
    04 May 2009
    Link to this post

    Hi!

    I have a problem with RadCalendar in Internet Explorer 7. When I want to change month it show me runtime error: "Object expected". What can cause this error? Is this a problem of RadCalendar?

  16. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    04 May 2009
    Link to this post
    Hi Paul,

    I am not sure that this is a problem of the RadCalendar control. You can give a try to the online demo http://demos.telerik.com/aspnet-ajax/calendar/examples/overview/defaultcs.aspx or debug the code if you have followed Chanan code.

    Regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  17. Cameron
    Cameron avatar
    42 posts
    Registered:
    27 Jul 2009
    08 Apr 2010
    Link to this post
    Thanks for the code snippets! Sometimes these forums have some great info!

    I'm running into something strange when I try to implement this - maybe someone has an answer. I can get the RadCalendar to appear on a page with dates highlighted that are coming from the Events module. When I hover over one of the dates, I see the title of the event and in the browser status bar I see the link that will be generated. However, when I click the date, the browser looks like it is loading the right event page, but instead the original page with the calendar is just displayed. Any ideas?

    Thanks!
  18. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    09 Apr 2010
    Link to this post
    Hello Michael Buchsbaum,

    Here is a simplified and more clear solution

    <telerik:RadAjaxLoadingPanel runat="server" ID="RadAjaxLoadingPanel1" Skin="Vista" ></telerik:RadAjaxLoadingPanel>
        <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" LoadingPanelID="RadAjaxLoadingPanel1" EnableAJAX="true" Width="250">
           <telerik:RadCalendar runat="server" ID="RadCalandar1" Skin="Black" AutoPostBack="true" Width="248" />
       </telerik:RadAjaxPanel>

    subscribe for this event in PageLoad

    RadCalandar1.DayRender += new Telerik.Web.UI.Calendar.DayRenderEventHandler(RadCalandar1_DayRender);


    You could form your NavigateUrl using StringFormat, because the RadCalendar does not know where the ContentView based control like EventsView is located.

    [Telerik.Web.UrlRewriterService("Telerik.Cms.Engine.ContentUrlRewriterService, Telerik.Cms.Engine")]
    public partial class CustomControls_EventsRadCalendar : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
     
            EventsView eventsView = new EventsView();
            eventsView.BehaviorMode = Telerik.Cms.Engine.WebControls.ContentView.BehaviorModes.Detail;
            Controls.Add(eventsView);
            RadCalandar1.DayRender += new Telerik.Web.UI.Calendar.DayRenderEventHandler(RadCalandar1_DayRender);
         
        }
     
        void RadCalandar1_DayRender(object sender, Telerik.Web.UI.Calendar.DayRenderEventArgs e)
        {
            var monthStart = e.View.MonthStartDate;
            var monthEnd = e.View.MonthEndDate;
            HttpContext context = HttpContext.Current;
     
     
            var cntManager = new ContentManager("Events");
            List<IMetaSearchInfo> filter = new List<IMetaSearchInfo>();
            filter.Add(new MetaSearchInfo(MetaValueTypes.DateTime, "Publication_Date", monthStart, SearchCondition.GreaterOrEqual));
            filter.Add(new MetaSearchInfo(MetaValueTypes.DateTime, "Publication_Date", monthEnd, SearchCondition.LessOrEqual));
            IList allItems = cntManager.GetContent(filter.ToArray());
     
            if (allItems.Count > 0)
            {
                foreach (IContent cnt in allItems)
                {
                    var obj = (DateTime)cnt.GetMetaData("Publication_Date");
     
                    if (e.Day.Date.Day == obj.Day && e.Day.Date.Month == obj.Month)
                    {
                        var link = new HyperLink();
                        link.Text = e.Day.Date.Day.ToString();
                        //HERE YOU SHOULD SET THE PATH WHERE THE EVENTSVIEW CONTROL RESIDES. IN THIS CONTROL I CREATED IT DYNAMICALLY
                        link.NavigateUrl = "http://localhost:3157/WorkProject3x/en/GR/uuu1" + cnt.UrlWithExtension;
                        link.BackColor = System.Drawing.Color.Red;
                        e.Cell.Controls.Add(link);
                        break;
     
                    }
                }
     
            }
        }
    }


    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.
Register for webinar
18 posts, 0 answered