Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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);
share|improve this question

1 Answer 1

up vote 1 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 at 2:05

Your Answer

 
discard

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.