Click to Rate and Give Feedback
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)

Visual Basic (Declaration)
<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
Visual Basic (Usage)
Dim instance As SPGridView
C#
[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.

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
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Using SPGridView with your own DataSet      Powlo - MSFT   |   Edit   |  

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 What's this?: Add a tag
Flag as ContentBug
Custom paging SPGridView      Sasa Popovic   |   Edit   |  
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
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker