SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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);

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"];

                    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?

share|improve this question

for starters, you are calculating start and end dates differently

  DateTime StartTime = Convert.ToDateTime(item["EventDate"]);
  DateTime EndTime   = Convert.ToDateTime(item["EndDate"]  ).Date;

You should also use Convert.ToBoolean() rather than casting it as x = (bool) object. I've seen the latter fail in strange ways and if that happens to be the case here, then you could be ending up with Recurrance being true when it shouldn't be.

share|improve this answer
sorry I should have cleared my code before i pasted it here. What you have indicated is what I started off with I added .Date extension to both StartTime and EndTime and forgot to delete .date when I pasted the code here and I also had Convert.ToBoolean() initially and saw examples that use (bool) so I thought I'd try it that way.. but the problem persists through all of those scenarios lol I initially thought it was which cast type i used and date part i used too!! – MyName Mar 15 '12 at 18:13
When you click on subsequent months in the calendar, does the first of the month change as it should or is it simply showing the same calendar after each click? – Dave Wise Mar 15 '12 at 18:18
Same calendar after each click – MyName Mar 15 '12 at 18:22
except the month is different – MyName Mar 15 '12 at 18:34
Blast... I just reread this whole post. I bet the root of the problem is that your DataBind() is in _load and is probably firing every time the page posts back, which resets all internal calendar data every page load. Try wrapping your DataBind() command in a if (!Page.IsPostBack) {} block – Dave Wise Mar 15 '12 at 19:14
up vote 0 down vote accepted

had to set the SPCalendarView's V4Rendering property to false to get it working (EnableV4Rendering="false"). Of course this isn't the best solution as this removes some functionality added onto the Calendar from SharePoint 2007.

Other things I have come across in my research was that this is definitely a VisualWebPart issue in particular the UserControl. I will edit this answer with the link.

A solution offered by others is updating the SharePoint server with the December2011 cumulative update. I will try that tomorrow, but for now that is the temporary solution.

&& Yes the HotFix I applied fixed it, here is the link:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.