If you want to add a SPGridView to an Application Page in SharePoint and link it to a DataSource, you will have to write some extra code for sorting and filtering. I found quite some examples on different blogs, but still had to find out things on my own. Especially because I couldn’t find any code example that used a DataView as return type. So I’m not going to describe in detail the complete process, but only the steps related to a DataView return type.

In your Application Page you will have to add a reference to your assembly containing the DataSource. Next you add a tag for the DataSource, give it an ID and reference this ID in the SPGridView DataSourceID attribute. If you want sorting and filtering, like I do in this example, you set AllowSorting and AllowFiltering to true. For the filtering you have to define the FilterDataFields, FilteredDataSourcePropertyName and the FilteredDataSourcePropertyFormat. Suppose I only display four fields (Name, Type, Status and Description) of our DataSource and I only want to filter on Type and Status.

(more…)