Problem with Calendar templates

6 posts, 0 answers
  1. Carl Sconnely
    Carl Sconnely avatar
    10 posts
    Member since:
    Mar 2010

    Posted 14 Mar 2011 Link to this post

     Hi Im building a calendar in which the headline of the entry is showed up and opon hover the radtooltip shows up..
    In order to do that I'm assuming I have to create a custom template for every entry since what shows up on the calendar is the id for each template...

    I have created database tables and have a loop that adds the special days to the radCalendar control: 
    when I run this it does fill the grid but it puts the date of the cell on each cell of the calendar which is not what I want.

    Do While dr.Read()
                     Dim d As New DateTime()
                     Dim s As String = ""
                     Dim NewDay As New RadCalendarDay(RadCalendar1)
                     If Not IsDBNull(dr("evnDate")) Then
                         d = dr("evnDate")
                         d = System.DateTime.Now
                     End If
                     NewDay.Date = New DateTime(d.Year, d.Month, d.Day)
                     If Not IsDBNull(dr("evnRepeats")) Then
                         s = dr("evnRepeats")
                     End If
                     Select Case s
                         Case "Monthly"
                             NewDay.Repeatable = RecurringEvents.DayAndMonth
                         Case "Daily"
                             NewDay.Repeatable = RecurringEvents.DayInMonth
                         Case "Weekly"
                             NewDay.Repeatable = RecurringEvents.Week
                         Case ""
                             NewDay.Repeatable = RecurringEvents.None
                     End Select
                     If Not IsDBNull(dr("evnToolTip")) Then
                         NewDay.ToolTip = dr("evnToolTip")
                     End If
                     '-------------------------------------TemplateID, but first Create TEmplate,
                     '                                   in order to create template create div
                     'Dim newT As New DayTemplate()
                     'newT.ID = cDiv.InnerHtml.Replace(" ", "")
                     'If RadCalendar1.CalendarDayTemplates.Contains(newT) Then
                     '    RadCalendar1.CalendarDayTemplates.Add(newT)
                     'End If
                     'NewDay.TemplateID = newT.ID
                     Dim cDiv As New System.Web.UI.HtmlControls.HtmlGenericControl("DIV")
                     cDiv.Attributes("class") = "rcTemplate rcDayMortgage"
                     If Not IsDBNull(dr("evnTemplateID")) Then
                         cDiv.InnerHtml = dr("evnTemplateID")
                     ElseIf dr("evnTemplateID") = "" Then
                         cDiv.InnerHtml = "Calendar Entry"
                         cDiv.InnerHtml = "Calendar Entry"
                     End If
                     cDiv.ID = cDiv.InnerText
                     Dim template As New CalendarCellContentTemplate(RadCalendar1, d, cDiv, NewDay.Repeatable)

    Then Also I have grabbed this piece of code from your website that implements Itemplate to add the template to the Grid

    Public Class CalendarCellContentTemplate
           Implements ITemplate
           Private cellContent As Control
           Public Sub New(ByVal calendarInstance As RadCalendar, ByVal cellDate As DateTime, ByVal cellContent As Control, _
                          ByVal repeat As Telerik.Web.UI.Calendar.RecurringEvents)
               Dim spec As RadCalendarDay
               Me.cellContent = cellContent
               spec = calendarInstance.SpecialDays(calendarInstance.SpecialDays.IndexOf(cellDate))
               If spec Is Nothing Then
                   spec = New RadCalendarDay()
                   spec.Date = cellDate
                   spec.TemplateID = "BirthdayTemplate"
               End If
               Dim template As New DayTemplate
               template.ID = cellContent.ID
               template.Content = Me
               spec.Repeatable = repeat
           End Sub
           Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements System.Web.UI.ITemplate.InstantiateIn
           End Sub
       End Class

  2. Tsvetina
    Tsvetina avatar
    2101 posts

    Posted 18 Mar 2011 Link to this post

    Hello Carl,

    If I understand you correctly, you would like to show  different tooltips for the special days than the default date tooltips. As long as you add days to the special days collection at the right place (dynamically or not) the ToolTip property should work as expected. A simplified example of dynamically added special days follows below:
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Dim NewDay As New RadCalendarDay(RadCalendar1)
            NewDay.Date = New DateTime(2010, 11, 12)
            NewDay.Repeatable = RecurringEvents.DayAndMonth
            NewDay.TemplateID = "BirthdayTemplate"
            NewDay.ToolTip = "Anne's Birthday"
        End If
    End Sub

    In other words, this should be done only on initial page load in order to work correctly.

    Kind regards,
    the Telerik team
  3. Carl Sconnely
    Carl Sconnely avatar
    10 posts
    Member since:
    Mar 2010

    Posted 18 Mar 2011 Link to this post

    Hi Tsvetina ,

    Thank you for quick response, what I actually want is to display the name of the event (what I call event Headline) in the cell of the calendar. For instance the cell of 24th of August  would display for example "The holiday feast" and if somebody hovers the mouse over it -it shows the ToolTip on it. 

    Now from I understand one has to create a new template for each special day in order for the Event Headline ( the contents of the cell) to be different because of the fact that what  actually appears in the cell is the the inner html of the template:

                        <telerik:DayTemplate ID="MortgageTemplate" runat="server">
                        <div class="rcTemplate rcDayMortgage">


    As you see above "mortgage" is what is going to appear in the cell, what I want is the event of headline instead..
  4. Tsvetina
    Tsvetina avatar
    2101 posts

    Posted 23 Mar 2011 Link to this post

    Hello Carl,

    Where are you adding your CalendarCellContentTemplate instances to the CalendarDayTemplates collection? You should be doing so in order for them to be applied:
    Dim cdt As New CalendarDayTemplate()
    Dim dt As New DayTemplate 
    With dt 
        .Content = cdt 
        .ID = "SomeId" 
    End With 
    Dim rcd As New RadCalendarDay 
    With rcd 
        .Date = d.Date 
        .TemplateID = "SomeId"
    End With 

    the Telerik team
  5. Carl Sconnely
    Carl Sconnely avatar
    10 posts
    Member since:
    Mar 2010

    Posted 25 Mar 2011 Link to this post

    Hi Tsvetina , thanks for a reply

    I'm putting the code that you sent me onto the codebehind and the vb complains about this line:

    Dim cdt As New CalendarDayTemplate()

    Do I have to import anything besides telerik to get this to compile?
  6. Tsvetina
    Tsvetina avatar
    2101 posts

    Posted 30 Mar 2011 Link to this post

    Hello Carl,

    This is the supposed name of the programmatically created day template, in your case try with:
    Dim cdt As New CalendarCellContentTemplate()

    the Telerik team
Back to Top