In SharePoint 2007 we could use the SPCalendarView control (Microsoft.SharePoint.WebControls) to display custom created calendar events (for example from a separate SQL table).

Most links I have seen out there seem to point back to this post:

In summary, things looked like this:

private SPCalendarView _view;

/// <summary>
/// Create the SharePoint calendar. Uses the SharePoint SPCalendarView object.
/// </summary>
protected override void CreateChildControls()
    _view = new SPCalendarView();
    _view.EnableViewState = true;
    _view.Width = Unit.Percentage(100);
    _view.DataSource = GetCalendarItems();

private SPCalendarItemCollection GetCalendarItems()
    // Create a new collection for the calendar items
    // This is an item with a start and end date.
    SPCalendarItemCollection items = new SPCalendarItemCollection();

    // Add the first dummy item
    SPCalendarItem item = new SPCalendarItem();
    item.StartDate = DateTime.Now;
    item.EndDate = DateTime.Now.AddHours(1);
    item.hasEndDate = true;
    item.Title = "First calendar item";
    item.DisplayFormUrl = "/News";
    item.Location = "Utrecht";
    item.Description = "This is the first test item in the calendar rollup";
    item.IsAllDayEvent = false;
    item.IsRecurrence = false;
    item.CalendarType = Convert.ToInt32(SPCalendarType.Gregorian);

A direct port of this doesn't work in 2010. In order for it to work, you need to add the following in CreateChildControls:

_view.EnableV4Rendering = false;

This is OK, but you don't get all the visual styling of 2010 (aka v4 styles). How can I get the v4 styling by creating custom SPCalendarItem objects?

This guy does a pretty good high-level comparison between the 2007 and 2010 SPCalendarView implementation. Bonus: he describes one way to color code the calendar items (think Outlook Client).

A highlight from this post with my emphasis added:

They broke the Calendar!

Not really, but is sure has changed. In 2007 the calendar was created entirely server side. The HTML sent to the browser was the final, ready to display HTML. All we needed to do was to write a little JavaScript and/or CSS to “customize” it.

Why it’s now a bit harder to code… In 2010 the data for the calendar is now asynchronously loaded using a JavaScript function call after the page is loaded.

As I suspected, it likely has to do with some Javascript library that the SharePoint Web Part is loading that the ASP.NET Web Part is loading.

I'd still like to understand this a bit more, so my next steps, when I get some time, are to create two versions of my custom web part. One that inherits from ASP.NET Web Part, the other from SharePoint.WebPartPages.WebPart. Put them on two different pages, and analyze the rendered markup looking for differences.

  • What happens if this property is set to true? In what way does it not work?
    – Alex Angas
    Commented Sep 15, 2010 at 7:14
  • None of the manually created SPCalendarItems are shown.
    – Brian
    Commented Sep 15, 2010 at 10:57

1 Answer 1


Here is a related post from MSDN forums. Someone suggested I try inheriting from “Microsoft.SharePoint.WebPartPages.WebPart” rather than “System.Web.UI.WebControls.WebParts.WebPart”.

I tried this and it worked. I was then able to see my custom SPCalendarItem entries on my SP2010 SPCalendarView.

I still have a few outstanding questions about this though.

  1. Isn't the best practice to inherit from the non-SharePoint specific WebPart class?
  2. What is the SP WebPart class adding that the other doesnt? Some javascript references?
  3. What if we didn't want a WebPart, but only a Server/UserControl?
  • If you want to follow on MSDN: social.technet.microsoft.com/Forums/en-US/…
    – Brian
    Commented Sep 16, 2010 at 13:38
  • I realise it's been a while since this post so you may already be aware of this, but the best fit for our system is to ask new questions as new questions, rather than trying to carry out a discussion. This means your posts will be easier to answer and also find for other people in the future.
    – Alex Angas
    Commented Jun 29, 2011 at 3:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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