This example shows you how to delete a row from your SPGridView control.
Note the two events OnRowDataBound and OnRowDeleting on the control, and also pay attention to the DataKeyNames property.
I’ve also used TemplateField, and added in a LinkButton for Delete. Note the CommandName and CommandArgument properties.
Essentially, in this example I’ve bound a collection of items (SPListItem) from a particular list (SPList). The CommandArgument evaluates the Title of the list item that is also part of the bound collection.
And on the OnRowDeleting event, I’ve retrieved the list item (SPListItem) title from the particular row using the RowIndex.
I was using the SPGridView control and had a particular SPListItemCollection as my data source. My data binding works fine, but I get the "One of more field types are not installed properly” error on GridViewRowDataBound event.
This was strange because I was casting the right fields and also made sure that they weren’t null. After spending considerable amount of time looking at this I found the culprit. It was my data source CAML query. Have a look at it below:
Have you found my error? If you have, then you’ve been CAMLing to much . Well below is my updated working query:
Do you see my error now? Yup, I had used U2U’s CAML builder and then copied the query and pasted it in. Unfortunately, I had forgotten to remove the <Query></Query> elements from it. Remember, it’s not needed when you use the SPQuery object.
Hope this saves you valuable time.
Recently while helping a particularly lager business division, I noticed that a SPGridView control that they needed kept throwing the error Value cannot be null. Parameter name: propName.
Further investigation into the code behind revealed nothing out of the ordinary. A document library as the data source and such. Eventually, I had a look at the custom control itself (.ascx) and discovered that they had “Grouping” enabled.
Grouping is possible with SPGridView, see Paul Robinson’s blog post here. But they had forgotten to include and specify the GroupField and GroupDisplayName properties. Once I got this done, everything began working as how it should have in the first place.