SPGridView class

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

Inheritance hierarchy


Namespace:  Microsoft.SharePoint.WebControls
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)


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


Exception Condition

AutoGenerateColumns is set to true.


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.


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


SPGridView members

Microsoft.SharePoint.WebControls namespace