Introduction:
Ajax Control Toolkit has introduced Accordion web control which allows providing multiple panes and displays one at a time1. It is built as a collection of AccordionPane web controls. This article shows an enhancement to have a Show All/ Collapse All feature which would allow to View or Collapse all the panes. The figures below show the Show All and Collapse All states with the suggested enhancement.

Figure 1: Show all panes

Figure 2: Collapse all panes
Implementation:
The core of the implementation is handled through a new JavaScript function (_expandAllPanes) added to the AjaxControlToolkit.AccordionBehavior.prototype found in AccordianBehavior.js file in the AjaxControlToolKit source. This article uses the version 10606 of the Ajax Control Toolkit which can be download from CodePlex at http://www.codeplex.com/AtlasControlToolkit/Release/ProjectReleases.aspx?ReleaseId=1813. The source for this function is shown in Figure 3.
The function takes a Boolean argument which tells whether the Accordion control needs to be in a Show All or a Collapse All mode. As a first step during both the Show All and Collapse All states, the selected index is reset (to -1) to not have any active panes. The control iterates through its panes collection, and resets their existing animation state. Depending on the input argument, the animation of each pane is set to either "fade in" (Show All) or "fade out" (Collapse All), and all the panes are either opened or closed respectively.

Figure 3: _expandAllPanes function added to the AccordionBehavior prototype
Demo:
The example shown in Figure 4 shows how to use the added newly added function via the client scripts shown in Figure 5. There are two buttons on the page which can be used to Show/Collapse all panes. There is a client side function associated with them which calls the _expandAllPanes function. A user can alternately use a single Checkbox with a Show All/Collapse All feature.

Figure 4 Example demonstrating the use of Show all/ Collapse all feature
The client side functions are simply a wrapper over _expandAllPanes function and are listed below in Figure 5.

Figure 5 JavaScript functions using the added expandAllPanes function
Conclusion:
By having a Show All/ Collapse All feature, the Accordion control can be used in multiple scenarios where one would want to get a complete snapshot of the data. Another useful scenario is to display parent-child relationships where the child collections may be in a collapsed mode and shown only when requested.
References:
http://ajax.asp.net/ajaxtoolkit/Accordion/Accordion.aspx
Disclaimer:
This article is a result of notes made by my understanding on this subject and is meant purely for educational purposes. Any resemblance to other material is un-intentional coincidence and should not be misconstrued as malicious or slanderous.

SIVAPosted Apr 27, 2012, 8:01 AM
How to close collapsible panel, when any one of accordion panels are open at runtime.
Reem HumaidanPosted Aug 3, 2011, 11:05 AM
I downloaded the demo but can not find AccordianBehavior.js file. Can you please attach expand_allPanes javascript so i can try it. Thanks a lot
Jenny KirkineskaPosted May 2, 2011, 1:43 PM
Deepak, does this script work for expanding all panes of a DataBound Accordion which has a HeaderTemplate and a ContentTemplate? If so, where exactly in the AccordionBehavior.js file should I be inserting your script? My JavaScript is pretty basic. Thanks for the help.
ErionPosted Apr 28, 2011, 10:41 AM
Thanks a lot for sharing!!
eva winnerPosted May 21, 2010, 8:17 AM
how add a new JavaScript function (_expandAllPanes)to the AjaxControlToolkit.AccordionBehavior.prototype found in AccordianBehavior.js file?
erion alitePosted Feb 10, 2009, 3:49 PM
1. Add this part of the code at the bottom of the page. Sys.Application.add_load( function() { AjaxControlToolkit.AccordionBehavior.prototype._expandAllPanes = function(openOrClose) { .... the rest is on the pick. Is not so bad to type. 2. follow the demo code as how to use it. enjoy
Luis VelozPosted Dec 17, 2008, 4:58 PM
do you have a working version for a newer version of the ajax controlkit?
Kevin MellottPosted Nov 6, 2007, 4:08 PM
I get errors in the code that is in Figure 5. when clicking on either the expand or collapse buttons, should I be using the id for the div that holds the accordion, div id=cs_FAQS1_Accordion. Also the version of the Accordion in my AJAX Toolkit doesnt have the code that is in Figure 3. I downloaded the zip file from the link you provided above. Thanks
lion canadyPosted Oct 18, 2007, 9:41 AM
thanks for this nice article but i want to ask how do i use it if i had a master page?