Tag Archive | SPGridView

Duplicate grouping in SPGRIDVIEW

I recommend one to read this blog if he/she is working on spgridview control.

I had a requirement of grouping the records in the grid based on a column, grouping is straight forward and can be achieved with just few lines of code.However, this used to generate duplicate grouping headers for the records in the grid.

 oSpGridView.AllowGrouping = true;
 oSpGridView.GroupField = “Status”;
 oSpGridView.GroupFieldDisplayName = “Status”;

I had to sort the records by columns (that is used for grouping) in the caml query before it is bound to the grid control.This is the line of code that did the trick for me.

 SPQuery oSortQuery = new SPQuery();

//Sorting by status.
 oQuery.Query = “<FieldRef Name=’Status’ Ascending=’True’ />”;
 SPListItemCollection oColl = oList.GetItems(oSortQuery);

We can then use the collection object to bind it to the grid control.