1

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");
pnlListVIew.Controls.Add(lvwp);
2

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.

  • 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! – Michael Colbs Apr 3 '14 at 2:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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