SP.View Class

SharePoint 2010

Last modified: July 09, 2010

Applies to: SharePoint Foundation 2010

Specifies a list view.


The following example creates an input button on an application page that orders the items on the Tasks list of the current site in descending alphabetic order.

<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
<script type="text/ecmascript" language="ecmascript">

    function runCode() {

        var clientContext = new SP.ClientContext.get_current();

        if (clientContext != undefined && clientContext != null) {
            var web = clientContext.get_web();

            var listCollection = web.get_lists();
            var list = listCollection.getByTitle("Tasks");
            var viewCollection = list.get_views();
            var view = viewCollection.getByTitle("All Tasks");

            var query = '<OrderBy><FieldRef Name=\'Title\' Ascending=\'False\' /></OrderBy>';


            clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));

    function onQuerySucceeded() {
        alert('Tasks list ordered in descending alphabetic order.');

    function onQueryFailed(sender, args) {
        alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());


    <input id="Button1" type="button" value="Run Code" onclick="runCode()" />