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

Syntax

'Declaration
Public Sub ApplyStyle ( _
    viewStyle As SPViewStyle _
)
'Usage
Dim instance As SPView
Dim viewStyle As SPViewStyle

instance.ApplyStyle(viewStyle)
public void ApplyStyle(
    SPViewStyle viewStyle
)

Parameters

Remarks

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.

Examples

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.

Dim siteCollection As SPSite = SPControl.GetContextSite(Context)
Dim site As SPWeb = siteCollection.AllWebs("Site_Name")
Dim list As SPList = site.Lists("List_Name")
Dim view As SPView = list.Views("All Items")
Dim intBoxed As Integer = 13

view.ApplyStyle(site.ViewStyles.StyleByID(intBoxed))

view.Update()
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();
}

Note

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.

See Also

Reference

SPView Class

SPView Members

Microsoft.SharePoint Namespace