I am creating a custom SharePoint Calendar to pull from multiple SharePoint Calendar Lists.
In the markup I have the following:
<SharePoint:SPCalendarView ID="EventsCalendar2" width="100%" runat="server"></SharePoint:SPCalendarView>
I bind it like this in page load after getting the site and list myItems is a SPListItemCollection:
EventsCalendar2.DataSource = MakeSchedule(myItems);
EventsCalendar2.DataBind();
The MakeSchedule(myItems) is the following:
private SPCalendarItemCollection MakeSchedule(SPListItemCollection myItems)
{
SPCalendarItemCollection items = new SPCalendarItemCollection();
for (int i = 0; i < myItems.Count; i++)
{
SPListItem item = myItems[i];
DateTime StartTime = Convert.ToDateTime(item["EventDate"]);
DateTime EndTime = Convert.ToDateTime(item["EndDate"]);
string Description = "";
if (item["Description"] != null)
Description = item["Description"].ToString();
string Location = "";
if (item["Location"] != null)
Location = item["Location"].ToString();
bool Recurrance = false;
if (item["fRecurrence"] != null)
Recurrance = (bool)item["fRecurrence"];
bool AllDayEvent = false;
if (item["fAllDayEvent"] != null)
AllDayEvent = (bool)item["fAllDayEvent"];
items.Add(
new SPCalendarItem()
{
ItemID = item["ID"].ToString(),
StartDate = StartTime,
EndDate = EndTime,
hasEndDate = true,
Title = item["Title"].ToString(),
Location = Location,
Description = Description,
IsAllDayEvent = AllDayEvent,
IsRecurrence = Recurrance,
CalendarType = (int)SPCalendarType.Gregorian
}
);
}
return items;
}
NOW I can't figure out why the events are being displayed in all of the months when they should only be displayed in the months specified by StartDate & EndDate. Any ideas on what I am doing wrong??
Could it be that the SPCalendarView control cannot be used in a VisualWebPart?