Field Grouping with SPGridView – More than one group returned for a single value

It is very easy to group by a field using the SharePoint SPGridView control. Just set some properties and your good to go.

resultsGridView.GroupField = “Status”;
resultsGridView.GroupFieldDisplayName = “Status”;
resultsGridView.GroupDescriptionField = “Description”;
resultsGridView.AllGroupCollapse = true;
resultsGridView.DisplayGroupFieldName = false;

However, depending on how your results are sorted, you may see that you get multiple groups for a single value. The way to fix this is to sort by the same field you are grouping by.

In this first example, I am grouping by “Status” and sorting only by “DueDate”

SPSiteDataQuery Group Error

In this example, I am still grouping by “Status” but now I am first sorting by “Status” and then by “Due Date”

SPSiteDataQuery Group No Error

You may not notice this issue right away. It all depends on the value of your results and how they are sorted.  So while it may work right off the bat, later on the issue may pop up!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.