SPGridView Class

Represents a grid view that looks and behaves like a SharePoint Foundation list view.

Inheritance Hierarchy

System.Object
  System.Web.UI.Control
    System.Web.UI.WebControls.WebControl
      System.Web.UI.WebControls.BaseDataBoundControl
        System.Web.UI.WebControls.DataBoundControl
          System.Web.UI.WebControls.CompositeDataBoundControl
            System.Web.UI.WebControls.GridView
              Microsoft.SharePoint.WebControls.SPGridView

Namespace:  Microsoft.SharePoint.WebControls
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: No

Syntax

'Declaration
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
Public Class SPGridView _
    Inherits GridView _
    Implements ICallbackEventHandler, IPostBackEventHandler
'Usage
Dim instance As SPGridView
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class SPGridView : GridView, ICallbackEventHandler, 
    IPostBackEventHandler

Exceptions

Exception Condition
InvalidOperationException

AutoGenerateColumns is set to true.

Remarks

The SPGridView control supports the cascading style sheets that are built intoMicrosoft SharePoint Foundation 2010. You can present data in a grid view that closely resembles the view that SharePoint Foundation 2010 uses to display data from lists. You can also sort and group rows.

This class does not support auto-generated columns. This means that you must explicitly bind each column using SPBoundField.

One way to populate the SPGridView control is to create an ADO.NET DataTable. You can then bind DefaultView to DataSource(), and then call DataBind(). You can do this by creating an ADO.NET DataTable or by using a query object, such as an SPSiteDataQuery object, that returns an ADO.NET DataTable. Additionally, you can use any ASP.NET data source control such as SPDataSource.

Examples

The following code shows how to set the values for this control.

<SharePoint:SPGridView runat="server"  ID="grdPropertyValues" AutoGenerateColumns="false" RowStyle-BackColor="#DDDDDD" AlternatingRowStyle-BackColor="#EEEEEE" />  

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

SPGridView Members

Microsoft.SharePoint.WebControls Namespace