2

I am devloping a SP2013 App which includes a page (aspx) that contains the following webpart and XsltListViewWebPart as shown below. I have managed to remove all the elements i want to remove (Toolbar, seaarchbox etc) but I want to specify the view (I have created 4 views for the list) that the list default to but I can see any option to do this?

Anyone achived this?

<WebPartPages:WebPartZone runat="server" FrameType="None" ID="HolidayBalance" Title="loc:HolidayBalance" PartChromeType="TitleOnly" ShowTitleIcons="True" AllowLayoutChange="False">
        <WebPartPages:XsltListViewWebPart ID="XsltListYourHolidayBalance" runat="server" ListUrl="Lists/Personnel Holiday Entitlement"  IsIncluded="True" NoDefaultStyle="TRUE" Title="Your Holiday Balance" PageType="PAGE_NORMALVIEW" Default="True" DisableViewSelectorMenu="True" InplaceSearchEnabled="False" ShowToolbarWithRibbon="False" >

7

If you plan to provision the page using a Module, I'd recommend configuring the web part inside of the Module, rather than in the aspx file itself. This will allow you to select whichever view you would want:

<File Path="mypage.aspx" Url="mypage.aspx" Type="GhostableInLibrary">
  <View List="Lists/Personnel Holiday Entitlement" BaseViewID="4" WebPartZoneID="HolidayBalance" WebPartOrder="1">
    <![CDATA[
          <webParts>
              <webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
                  <metaData>
                      <type name="Microsoft.SharePoint.WebPartPages.XsltListViewWebPart,Microsoft.SharePoint,Version=14.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" />
                      <importErrorMessage>Cannot import this Web Part.</importErrorMessage>
                  </metaData>
                  <data>
                      <properties>
                          <property name="Title" type="string">Your Holiday Balance</property>
                          <property name="DisableViewSelectorMenu" type="bool">True</property>
                          <property name="InplaceSearchEnabled" type="bool">False</property>
                          <property name="ShowToolbarWithRibbon" type="bool">False</property>
                      </properties>
                  </data>
              </webPart>
          </webParts>
      ]]>
  </View>
</File>

Note: this example is from SP 2010, hopefully it's applicable and compatible with SP 2013.

2
  • Hey Rich, thanks for that, have just arrive at the same conclusion! Slightly annoying that my VS intelisense does not seem to work inside <![CDATA[ but at least i can do what i need to do.
    – Stephen
    Feb 14 '13 at 17:32
  • I should have listened, found this a week ago. I changed Version to 15.0.0.0 for SP2013. I also used this blog.ozippy.com/2011/04/… to provision my view correctly and changed the BaseViewID to match. Perfect thanks.
    – Matthew R
    Jul 17 '14 at 13:47
2

If you want to change it pro-grammatically check this link out. Where they getting the webpart and then setting it's view.

create or get XsltListViewWebPart

You can change default view in the definition of your list too.

Here's a similar question on SE that explains how to change list's default view in Schema.xml

3
  • Thanks for the reply...yes I have seen this but I am displaying the list twice on the same page...for 1 list I want to show the default view (all) and in the other list a custom view...Does this mean i need to create two lists containing the exact same content?!
    – Stephen
    Feb 14 '13 at 12:47
  • I see, since you will have 2 webparts and I assume with different titles, then pro-grammatical approach should work as get each webpart using there title. Feb 14 '13 at 12:50
  • Yip i have two different web parts, its seems crazy i can specify the view in the tags for the XsltListViewWebPart.
    – Stephen
    Feb 14 '13 at 12:52

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.