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

[Solved] Hiding Collaps/Expand icon when no sub-items

2 Answers 116 Views
Grid
This is a migrated thread and some comments may be shown as answers.
egoren
Top achievements
Rank 1
egoren asked on 17 Jul 2009, 09:44 PM
Hi,
I've got a few questions related to the expand/collaps column:
1. Is there a way to hide the expand/collaps columns when there are no sub-items for a row
2. is there a way to hide the expand/collaps column itself if none of the rows has sub-items
3. I would like to add a collaps All rows/Expand All rows button

Thanks in advance, Eyal.

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 20 Jul 2009, 07:57 AM
Hello Eyal,

You can go through the following help document, to hide the expand/collapse images when there are no records under the parent grid item:
Hiding expand/collapse images when no records

You can add the ExpandAll and CollaoseAll to the CommandItemTemplate and try the following code:
aspx:
<CommandItemTemplate> 
      <asp:LinkButton ID="btnExpandAll" CommandName="ExpandAll"  runat="server">ExpandAll</asp:LinkButton> 
      <asp:LinkButton ID="btnCollapseAll" CommandName="CollapseAll"  runat="server">CollapseAll</asp:LinkButton> 
</CommandItemTemplate> 

c#:
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
    { 
        if (e.CommandName == "ExpandAll"
        { 
            foreach (GridDataItem item in RadGrid1.MasterTableView.Items) 
            { 
                if (!item.Expanded) 
                    item.Expanded = true
            } 
        } 
 
        if (e.CommandName == "CollapseAll"
        { 
            foreach (GridDataItem item in RadGrid1.MasterTableView.Items) 
            { 
                if (item.Expanded) 
                    item.Expanded = false
            } 
        } 
    } 

Thanks
Princy.
0
egoren
Top achievements
Rank 1
answered on 23 Jul 2009, 09:25 PM
Thank you Princy for the quick response.
Your answers were both right on the money and we have integrated them into our application. I have found two issues with the 'Hiding expand/collapse images when no records' article and I have notified Telerik about them so hopefully it will be updated soon. Thanks again, Eyal.
Tags
Grid
Asked by
egoren
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
egoren
Top achievements
Rank 1
Share this question
or