Telerik RadCalendar - Specialdays : How to display Date of the Special Day
I am not familiar with RadCalendar component. Pleas bear with me if my question is a basic functionality.
My purpose is to display selected days with different BackColor values, according to the selection of the client. Basically only changing the ItemStyle for the selected days are acceptable for me, but I couldn't find how to do it? So I tried a differen approach as follows:
I created SpecialDays in my Calendar
<telerik:RadCalendar AutoPostBack="true" ID="calendar1" runat="server" Width="400px" Height="300px" FirstDayOfWeek="Monday">
<SpecialDays>
<telerik:RadCalendarDay TemplateID="temp1"></telerik:RadCalendarDay>
</SpecialDays>
<SpecialDays>
<telerik:RadCalendarDay TemplateID="temp2"></telerik:RadCalendarDay>
</SpecialDays>
<SpecialDays>
<telerik:RadCalendarDay TemplateID="temp3"></telerik:RadCalendarDay>
</SpecialDays>
<CalendarDayTemplates>
<telerik:DayTemplate ID="temp1" runat="server">
<Content>
<asp:Label ID="lblTemp1" runat="server"></asp:Label>
</Content>
</telerik:DayTemplate>
<telerik:DayTemplate ID="temp2" runat="server">
<Content>
<asp:Label ID="lblTemp2" runat="server"></asp:Label>
</Content>
</telerik:DayTemplate>
<telerik:DayTemplate ID="temp3" runat="server">
<Content>
<asp:Label ID="lblTemp3" runat="server"></asp:Label>
</Content>
</telerik:DayTemplate>
</CalendarDayTemplates>
</telerik:RadCalendar>
And in code behind, I am assiging the selected days to the desired template when the client press the button of choice as SetAstemp1, SetAstemp2 or SetAstemp3:
protected void BtnSetAsTemp1_Click(object sender, EventArgs e)
{
int daysCount = calendar1.SelectedDates.Count;
for (int i = 0; i < daysCount; i++)
{
RadCalendarDay day = new RadCalendarDay();
day.TemplateID = "temp1";
day.Date = calendar1.SelectedDates[i].Date;
calendar1.SpecialDays.Add(day);
}
}
But with this approach, I cannot use the embedded skin in RadCalendar control. When the selected day is assigned to a special day, the date of the cell is not displayed. And I have to show the date in Content tag of the related SpecialDay. But I could not find a way to access the lblTemp1 control defined in the Content.
Could you please point me to the right direction开发者_Go百科 if my approach is not right? Or any suggestions to display the date in the lblTemp1.Text is appreciated.
Thank you!
Impulse, I think that the simplest method is to set the backcolors for selected dates hooking the DayRender event of the Telerik calendar. I found this online example that might be useful to you.
RadCalendarDay holiday = new RadCalendarDay();
holiday.Date = Datetime.Now;//Your date which you want
holiday.IsSelectable = false;
holiday.IsDisabled = true;
holiday.ToolTip = "NOT AVAILABLE";
TableItemStyle style = new TableItemStyle();
style.BackColor = Color.HotPink;
holiday.ItemStyle.CopyFrom(style);
calendar1.SpecialDays.Add(holiday);
精彩评论