The Sharepoint SPGridView control seems to be rendered as expanded sometimes, although it should be collapsed.
Here is a javascript function to fix this issue:
function spGridViewFixExpandedGroups(gridviewId) {
var gridview = $("[id$='" + gridviewId + "']");
var links = gridview.find("tr[isexp='true'] a[title='Expand/Collapse']");
links.click();
}
Simply call the script upon page load. Note: The script requires the jQuery library to be included.
It solved my problem