A session variable is used to persist the state of the Expanded property for each group header item. The outer test in the ItemDataBound routine only allows GridGroupHeaderItems to be controlled. The session variable name is the UniqueID of the item in the grid. The following code shows how to keep the groups collapsed/expanded after an autopostback.
Private Sub RadGrid2_ItemDataBound(sender As Object, e As GridItemEventArgs) Handles RadGrid2.ItemDataBound
' Save expanded state of the header item
If TypeOf e.Item Is GridGroupHeaderItem Then
If Session(e.Item.UniqueID) IsNot Nothing Then
e.Item.Expanded = CBool(Session(e.Item.UniqueID))
Else
e.Item.Expanded = True
Session(e.Item.UniqueID) = True
End If
End If
End Sub
Private Sub RadGrid2_ItemCommand(sender As Object, e As GridCommandEventArgs) Handles RadGrid2.ItemCommand
If e.CommandName = RadGrid.ExpandCollapseCommandName Then
Session(e.Item.UniqueID) = Not e.Item.Expanded
End If
End Sub
The Else portion of the test in RadGrid2_ItemDataBound determines if the groups are expanded (True) or collapsed (False) when the form is initially displayed.