This is a migrated thread and some comments may be shown as answers.

Problem with Calendar templates

5 Answers 102 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Carl Sconnely
Top achievements
Rank 1
Carl Sconnely asked on 14 Mar 2011, 08:19 PM
 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)
                 '---------------------------------Date
                 If Not IsDBNull(dr("evnDate")) Then
                     d = dr("evnDate")
                 Else
                     d = System.DateTime.Now
                 End If
 
                 NewDay.Date = New DateTime(d.Year, d.Month, d.Day)
                 '---------------------------------Repeat
                 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
                 '-------------------------------------Tooltip
                 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.Controls.Add(cDiv)
                 'newT.ID = cDiv.InnerHtml.Replace(" ", "")
 
 
 
                 'If RadCalendar1.CalendarDayTemplates.Contains(newT) Then
                 '    RadCalendar1.CalendarDayTemplates.Add(newT)
                 'End If
                 'NewDay.TemplateID = newT.ID
 
                 'RadCalendar1.SpecialDays.Add(NewDay)
 
                 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"
                 Else
                     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"
               calendarInstance.SpecialDays.Add(spec)
           End If
 
           Dim template As New DayTemplate
           template.ID = cellContent.ID
           template.Content = Me
 
           spec.Repeatable = repeat
           calendarInstance.CalendarDayTemplates.Add(template)
       End Sub
 
       Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements System.Web.UI.ITemplate.InstantiateIn
           container.Controls.Add(Me.cellContent)
       End Sub
   End Class

5 Answers, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 18 Mar 2011, 08:29 AM
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"
        RadCalendar1.SpecialDays.Add(NewDay)
    End If
End Sub

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

Kind regards,
Tsvetina
the Telerik team
0
Carl Sconnely
Top achievements
Rank 1
answered on 18 Mar 2011, 08:05 PM
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:

                       <CalendarDayTemplates>
                       
                    <telerik:DayTemplate ID="MortgageTemplate" runat="server">
                <Content>
                    <div class="rcTemplate rcDayMortgage">
                        mortgage
                    </div>
                </Content>
            </telerik:DayTemplate>

                        
                    </CalendarDayTemplates> 

As you see above "mortgage" is what is going to appear in the cell, what I want is the event of headline instead..
0
Tsvetina
Telerik team
answered on 23 Mar 2011, 04:08 PM
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 
cal.CalendarDayTemplates.Add(dt) 
Dim rcd As New RadCalendarDay 
With rcd 
    .Date = d.Date 
    .TemplateID = "SomeId"
End With 
cal.SpecialDays.Add(rcd)


Regards,
Tsvetina
the Telerik team
0
Carl Sconnely
Top achievements
Rank 1
answered on 25 Mar 2011, 03:24 PM
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?
0
Tsvetina
Telerik team
answered on 30 Mar 2011, 02:03 PM
Hello Carl,

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

Greetings,
Tsvetina
the Telerik team
Tags
Calendar
Asked by
Carl Sconnely
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Carl Sconnely
Top achievements
Rank 1
Share this question
or