SPGridView Class
Represents a grid view that looks and behaves like a SharePoint Foundation list view.
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: No
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)] [AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)] public class SPGridView : GridView, ICallbackEventHandler, IPostBackEventHandler
| Exception | Condition |
|---|---|
| InvalidOperationException |
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.
- 2/29/2012
- Mohamed.Ramadan
- 3/4/2012
- Mohamed.Ramadan
Unable to cast object of type 'System.Int32' to type 'System.String'
void spgvGrid_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
spgvGrid.PageIndex = e.NewPageIndex; //throws the error
spgvGrid.DataBind();
}
I removed the error with removing the DataKeyNames="ID" from SPGridView. Because of that i had to get the ID of all checked checkboxs as suggested here:
http://blog.sharepointsite.co.uk/2010/10/spdatagrid-error-unable-to-cast-object.html
Is this a bug?
Regards,
Mark
- 6/23/2011
- maresplace
SPGrdiView = new SPGridView();
spGridView.AutoGenerateColumns = false;
spGridView.EnableTheming = true;
// RowStyle-BackColor="#DDDDDD" AlternatingRowStyle-BackColor="#EEEEEE"
spGridView.RowStyle.BackColor = System.Drawing.Color.Aqua;
spGridView.AlternatingRowStyle.BackColor = System.Drawing.Color.AntiqueWhite;
- 9/20/2010
- Vijay Gande
Is it possible to bind data to the spgridview control by using SqlDatasource etc. as like object data source.
- 8/10/2010
- Manishrao Patil