Showing posts with label DataKeyNames. Show all posts
Showing posts with label DataKeyNames. Show all posts

Friday 29 October 2010

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.

More info:
http://www.sharepointoverflow.com/questions/4481/using-code-compiled-for-moss-2007-in-2010