<SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel:=True)> _ <AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level:=AspNetHostingPermissionLevel.Minimal)> _ <SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel:=True)> _ <AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level:=AspNetHostingPermissionLevel.Minimal)> _ Public Class SPGridView Inherits GridView Implements ICallbackEventHandler, IPostBackEventHandler
Dim instance As SPGridView
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel=true)] [AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)] [SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel=true)] [AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)] public class SPGridView : GridView, ICallbackEventHandler, IPostBackEventHandler
SPGridView supports the Cascading Style Sheets built into WSS. You can present data in a grid view that closely resembles the view that SharePoint uses to display data from lists. You can also sort and group rows.
This class does not support auto-generated columns. That means you must explicitly bind each column using SPBoundField. You can do this by creating an ADO.NET DataTable or by using a query object that return an ADO.NET DataTable object, such as an SPSiteDataQuery object.
Note Make sure to set AutoGenerateColumns=false. If you set AutoGenerateColumns=true an exception will be thrown.
<SharePoint:SPGridView
runat="server"
ID="grdPropertyValues"
AutoGenerateColumns="false"
RowStyle-BackColor="#DDDDDD"
AlternatingRowStyle-BackColor="#EEEEEE" />
One way to populate the SPGridView control is to create an ADO.NET DataTable. You can bind the DefaultView property of a DataTable to the DataSource property of the SPGridView control, and then call the DataBind method.
If you'd like to use SPGridView with your own DataSet data, or with a class which inherits from DataSource, have a look at these blog entries:
Creating a web part with an SPGridView control, adding sorting, grouping and custom menus.
http://blogs.msdn.com/powlo/archive/2007/02/25/displaying-custom-data-through-sharepoint-lists-using-spgridview-and-spmenufield.aspx
Adding paging:
http://blogs.msdn.com/powlo/archive/2007/03/23/adding-paging-to-spgridview-when-using-custom-data-sources.aspx
http://msdn.microsoft.com/en-us/library/bb466219.aspx