Search This Blog

Friday, October 10, 2014

SPGridView explained

SPGridView explained

Overview:  The SPGridView is similar to the asp GridView.  The SPGridView is derived from the aspGridView and has additional functionality.  The SPGridView does not support the property AutoGenerateColumns, you must specify each SPBoundField.

Example: SPBoundFields such as "BoundField" are used to display datasource columns.
 
Example: To format a bound column use the property "DataFormatString", e.g. colDate.DateFormatString = "{0:d}";, this will display the short date only from a DateTime type.  If you need more advanced formating such as for a multi choice field, create a new class that derives from BoundField and use it in the SPGridView.

Tip: Don't use DataKeyName on the SPDataGrid, it causes the error "Unable to cast object of type 'System.Int32' to type 'System.String'.".

SPDataGrid error 'Unable to cast object of type int32 - SPDataGrid.NewPageIndex property and DataKeyNames

Problem: SPDataGrid can't use DataKeyNames, it results in the error "Unable to cast object of type 'System.Int32' to type 'System.String'." when paging or filtering.


Hypothesis: This looks like a bug in the implementation of the SPGridView.  The property DataKeyNames causes the error.

Resolution: To pass values using buttons or check boxes inside you SPGridView rather use the row index to get the row and read the Id or data you need from the row.




Read More:
http://msdn.microsoft.com/en-us/library/bb466219(office.12).aspx

No comments:

Post a Comment