Export (0) Print
Expand All

SPView.ApplyStyle Method

Applies the specified style to the view.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online

public void ApplyStyle(
	SPViewStyle viewStyle
)

Parameters

viewStyle
Type: Microsoft.SharePoint.SPViewStyle
The view style to be applied.

Call the Update method to save these changes in the database.

The StyleByID(Int32) method returns the IDs and names of the view styles that are included in an original installation of Microsoft SharePoint Foundation.

The following code example applies a Boxed style to the All Items view for a specified list in a site of the current site collection.

SPSite oSiteCollection = SPContext.Current.Site;
using(SPWeb oWebsite = oSiteCollection.AllWebs["Website_Name"])
{
    SPList oList = oWebsite.Lists["List_Name"];
    SPView oView = oList.Views["All Items"];
    int intBoxed = 13;

    oView.ApplyStyle(oWebsite.ViewStyles.StyleByID(intBoxed));

    oView.Update();
}
NoteNote

Certain objects implement the IDisposable interface, and you must avoid retaining these objects in memory after they are no longer needed. For information about good coding practices, see Disposing Objects.

Community Additions

ADD
Show:
© 2014 Microsoft