Microsoft.SharePoint.WebCon ...


SPGridView Class (Microsoft.SharePoint.WebControls)
Represents a grid view that looks and behaves like a tree view.

Namespace: Microsoft.SharePoint.WebControls
Assembly: Microsoft.SharePoint (in microsoft.sharepoint.dll)
Syntax

Visual Basic (Declaration)
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel:=True)> _
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level:=AspNetHostingPermissionLevel.Minimal)> _
<SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel:=True)> _
<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level:=AspNetHostingPermissionLevel.Minimal)> _
Public Class SPGridView
    Inherits GridView
    Implements ICallbackEventHandler, IPostBackEventHandler
Visual Basic (Usage)
Dim instance As SPGridView
C#
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel=true)] 
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)] 
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel=true)] 
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)] 
public class SPGridView : GridView, ICallbackEventHandler, IPostBackEventHandler
Remarks

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.

Example

<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.

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
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

Tags :


Community Content

Powlo - MSFT
Using SPGridView with your own DataSet

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

 

Tags :

Sasa Popovic
Custom paging SPGridView
I made a class that inherits from SPGridView and allows custom paging. Using that class you can bind to grid only the rows/items that should be shown on a particular page and not the whole result set. It is very usefull in cases when you have a very large result sets and don't want to fetch the whole result set from database and bind it to grid. I published my control on CodePlex so that everyone can use it: http://www.codeplex.com/aspnetlibrary

azra2009
Visual How To - SPGridView

http://msdn.microsoft.com/en-us/library/bb466219.aspx



Tags : spgridview

JennyQ
What is the difference between SPGridView and GridView?
What is the difference between Microsoft.SharePoint.WebControls.SPGridView and System.Web.UI.WebControls.GridView?
Tags : contentbug

Pedro Mateus
whats wrong with grouping?
When i enable grouping and then sort the rows i get weird groups... and some times the first group doesnt get the (+) expand...anyone is having this problem?

Page view tracker