Hi
I've tried to add some custom text dynamically from code behind to the calendardays based on some different code examples. It's working fine on pageload and all events is displayed in the calendar for the current month. But I'm not able to change month and display events from other months. In fact i can only switch month one time ex: from jan -> feb.
I've tried a coupe of different code examples all with the same month-problem. Any idea what I'm doing wrong?
I've tried to add some custom text dynamically from code behind to the calendardays based on some different code examples. It's working fine on pageload and all events is displayed in the calendar for the current month. But I'm not able to change month and display events from other months. In fact i can only switch month one time ex: from jan -> feb.
I've tried a coupe of different code examples all with the same month-problem. Any idea what I'm doing wrong?
protected
override
void
OnInit(EventArgs e)
{
Hashtable eventHash = GetEventCollection(
false
);
DateTime rcDate = RadCalendar1.CalendarView.ViewStartDate;
while
(rcDate <= RadCalendar1.CalendarView.ViewEndDate)
{
string
key = rcDate.ToString(
"yyyy-MM-dd"
);
if
(eventHash.ContainsKey(key))
{
List<Event> eventList = (List<Event>)eventHash[key];
CalendarDayTemplate template =
new
CalendarDayTemplate(RadCalendar1, rcDate, eventList.Count);
}
rcDate = rcDate.AddDays(1.0);
}
base
.OnInit(e);
}
public
class
CalendarDayTemplate : ITemplate
{
private
Control cellContent =
new
Control();
public
CalendarDayTemplate(RadCalendar myCalendar, DateTime cellDate,
int
myData)
{
RadCalendarDay newDay =
new
RadCalendarDay();
PlaceHolder myPlaceHolder =
new
PlaceHolder();
Page myPage =
new
Page();
HtmlGenericControl divContainer =
new
HtmlGenericControl(
"div"
);
divContainer.Attributes.Add(
"class"
,
"CalendarDayContainer"
);
HtmlGenericControl divDate =
new
HtmlGenericControl(
"div"
);
divDate.Attributes.Add(
"class"
,
"Date"
);
divDate.InnerText = cellDate.Day.ToString();
divContainer.Controls.Add(divDate);
HtmlGenericControl divEvent =
new
HtmlGenericControl(
"div"
);
divEvent.Attributes.Add(
"class"
,
"Event"
);
if
(myData > 0)
divEvent.InnerText =
string
.Concat(myData,
" events"
);
divContainer.Controls.Add(divEvent);
myPlaceHolder.Controls.Add(divContainer);
this
.cellContent = myPlaceHolder;
// Create a DayTemplate with a unique ID
DayTemplate dayTemplate =
new
DayTemplate();
dayTemplate.ID = cellDate.ToString(
"MMddyyyy"
);
dayTemplate.Content =
this
;
// create a SpecialDay, associate it with the DayTemplate and add to Calendar
newDay.Date = cellDate;
newDay.TemplateID = dayTemplate.ID;
myCalendar.SpecialDays.Add(newDay);
myCalendar.CalendarDayTemplates.Add(dayTemplate);
}
// Once the RadCalendar is instantiated this will be called once for each cell
public
void
InstantiateIn(Control container)
{
container.Controls.Add(
this
.cellContent);
}
}