SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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 adding a XsltListViewWebPart dynamically to an asp Panel. This code works except I cannot get the calendar view to display. Despite specifying the guid, a regular list view will appear (Even though the 'Calendar' view is selected on load). Any suggestions? ty

SPWeb oWebsite = SPContext.Current.Web;
SPList oList = oWebsite.Lists["Events"];
SPView view = oList.Views["Calendar"];    
XsltListViewWebPart lvwp = new XsltListViewWebPart();
lvwp.ListDisplayName = "Events";
lvwp.ViewFlags = SPViewFlags.Calendar;
lvwp.ViewId = Int32.Parse(view.BaseViewID);
lvwp.ViewGuid = view.ID.ToString("B");
share|improve this question
up vote 2 down vote accepted

I also had this problem. The solution for me was to use Listviewwebpart and not Xsltlistviewwebpart. That is also What Sharepoint is doing behinhd the scene when you set à calendar view from the Gui.

share|improve this answer
It was a while ago, but I think is was using SP 2010 for this as SharePoint 2013, every List View Web Part is XSL or JSLink. Thanks for sharing though! – Colbs Apr 3 '14 at 2:05

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.