This is a migrated thread and some comments may be shown as answers.

Radgrid Expand Group/Collapse single group

3 Answers 485 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
John asked on 12 Jan 2016, 12:26 PM


What I want to achieve is very simple. I have a standard grid that may be grouped by one of the columns. This is achieved using standard RadGrid functionality.

When the user clicks on the chevron of a group I want to toggle the group (expand or collapse it).There seem to be several threads on this type of thing. However, having looked at some of them what is not  clear to me is what is the correct approach.

Some of the questions that arise are

  • Do I have to implement a solution client side?  (I would prefer a server side solution.)
  • Do I need to implement something in page Page_PreRender(). 
  • Does the grid need to be rebound at any point? If so, where?

If somebody could point me to a simple example of this I would be very thankful. Ideally, the solution would be server side. By the way, I presume that I need to do the following (see below). However, I am not sure "what goes here", if anything?

Thanks in advance,


protected void GridItemCommand(object source, GridCommandEventArgs e)
      if (e.CommandName.Equals("ExpandCollapse"))
          // what goes here ???





3 Answers, 1 is accepted

Sort by
Top achievements
Rank 1
answered on 12 Jan 2016, 03:24 PM

OK. I have looked at this some more. From what I understand now, no special handling may be required in the code behind. The grouping should work by default and it should be possible to expand/collapse the groups as I require.

I am wondering if there is something particular about my grid? I have posted the mark up below. Perhaps I am missing something or something needs to be removed.

Thanks in advance,


<telerik:RadGrid ID="FooListGrid" runat="server" GridLines="None" AllowSorting="true" SkinID="DynamicPageSize"
    OnItemDataBound="FooraryListGridItemDataBound" AllowMultiRowSelection="True" OnItemCommand="FooItemCommand"
    OnNeedDataSource="FooListGridNeedsDataSource" OnPrerender="FooListGridPrerender"
    Height="100%" SelectColumnVisible="True" OnRowDrop="FooListGridOnRowDrop">
    <ItemStyle Height="60px" />
    <AlternatingItemStyle Height="60px" />
    <ClientSettings AllowDragToGroup="True" AllowRowsDragDrop="True" AllowColumnsReorder="false">
        <Scrolling AllowScroll="true" UseStaticHeaders="True" />
        <ClientEvents OnCommand="ValidateFilter" OnRowDropping="FooListGridOnRowDropping" />
        <Selecting AllowRowSelect="True" EnableDragToSelectRows="False" />
    <MasterTableView TableLayout="Fixed" NoMasterRecordsText="Empty"
        NoDetailRecordsText="Empty" OverrideDataSourceControlSorting="True"
        DataKeyNames="FooID,BarID" ClientDataKeyNames="FooID,BarID">
            <telerik:GridDragDropColumn UniqueName="DragDropColumn" HeaderStyle-Width="20px" ItemStyle-Width="20px" />
            <telerik:GridNumericColumn DataField="FooID" UniqueName="FooID" HeaderText="ID"/>
            <telerik:GridBoundColumn DataField="Name" HeaderText="Name" UniqueName="Name" SortExpression="Name" />
            <telerik:GridNumericColumn HeaderText="W" UniqueName="Width" DataField="Width" SortExpression="Width"
                FilterControlWidth="130" />
            <telerik:GridNumericColumn HeaderText="H" UniqueName="Height" DataField="Height" SortExpression="Height" FilterControlWidth="130" />
            <telerik:GridNumericColumn HeaderText="Size(bytes)" DataField="Size" UniqueName="Size"
                SortExpression="Size" FilterControlWidth="130" />
            <telerik:GridBoundColumn DataField="Extension" HeaderText="Ext" UniqueName="Extension"
                SortExpression="Extension" HeaderStyle-Width="80px" ItemStyle-Width="80px" FilterControlWidth="130">
                    <telerik:RadComboBox ID="FilterCombo" runat="server" AutoPostBack="false" AppendDataBoundItems="true"
                        SelectedValue='<%# Container.OwnerTableView.GetColumn("Extension").CurrentFilterValue %>'>
                            <telerik:RadComboBoxItem Text="No filters." Value="" />
            <telerik:GridTemplateColumn UniqueName="Thumbnail" HeaderText="Image" AllowFiltering="False" Groupable="False" HeaderStyle-Width="170px">
                    <asp:Image ID="locationImage" runat="server"
                        ImageUrl='<%# Bind("ThumbnailImageURL") %>' ToolTip='<%# Bind("FileName") %>'
                        AlternateText='<%# Bind("FileName") %>'
                        Style="cursor: pointer;" />
                    <asp:Label runat="server" ID="ImageDescription" CssClass="thumbnail-image-description" Text='<%# Bind("ImageDescription") %>' />
            <telerik:GridNumericColumn DataField="BarID" UniqueName="BarID"
                SortExpression="Size" FilterControlWidth="130" Display="False" />
            <telerik:GridDateTimeColumn DataField="DateUploaded" UniqueName="DateUploaded" Display="False" />
            <telerik:GridBoundColumn DataField="FileName" HeaderText="FileName" UniqueName="FileName"
                SortExpression="FileName" Display="False" />
            <telerik:GridBoundColumn DataField="FooraryCategoryName" HeaderText="Folder Name" UniqueName="FooraryCategoryName"
                SortExpression="FooraryCategoryName" Display="True" />
    <PagerStyle AlwaysVisible="True" />

Telerik team
answered on 15 Jan 2016, 05:16 AM
Hello John,

Could you verify that you are not using DataBind() to bind the grid? Performing complex grid operations such as Inserting, Deleting, Updating, Hierarchy relations, Grouping, Exporting, Paging, Sorting, Filtering, etc. require accommodating appropriate database operations.  Therefore, we suggest you to avoid Simple Databinding and strongly recommend the use of more advanced databinding methods, which automatically handle the aforementioned functions:
Declarative DataSource
Programmatic Data Binding

I can see that you are using NeedDataSource event, just make sure that you are not calling DataBind or Rebind in some generic place like Page_Load. Other than that the mark-up seems fine:

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Top achievements
Rank 1
answered on 19 Jan 2016, 05:23 PM
OK Eyup. Thanks very much for the reply. I will check.
Asked by
Top achievements
Rank 1
Answers by
Top achievements
Rank 1
Telerik team
Share this question