SIGN UP MEMBER LOGIN:    
ARTICLE

Rich AJAX Toolkit control: Accordion

Posted by Purushottam Rathore Articles | AJAX in C# April 28, 2009
Through this article I am going to introduce about AJAX Accordion Control.
Reader Level:

The Accordion control is used to specify a set of panes, similar to the famous menu in Microsoft Outlook. Each pane is made up of a header template and a content template. The header templates of all panes are always visible, while only one content template is visible. The user selects which pane to view by clicking on the header. The content from the previously active pane is hidden from view, and the content of the newly selected pane is displayed instead.

There are the following properties of Accordion control:

  • FadeTransitions
  • TransitionDuration
  • FramesPerSecond
  • SelectedIndex
  • AutoSize
  • Height etc.

The Accordion control can provide a fade transition when switching among active panes. You set the FadeTransitions property to true and can set the TransitionDuration and FramesPerSecond values. The default values are 250 milliseconds and 40 frames per second, respectively.

The SelectedIndex property lets you declaratively and programmatically control which pane to show.

The AutoSize property is None by default, meaning that the size of the Accordion control changes based on the active pane. Other content on the screen may be shifted to accommodate the changing size. But when the AutoSize property is set to Limit, the size is restricted to the Height value. The active pane will display scroll bars if the content is larger than the space available. The other possible value is Fill, which will result in expanding a pane if the content is not large enough to satisfy the Height value provided.

Example:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Accordian.aspx.cs" Inherits="Accordian" %>
<%
@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<
head id="Head1" runat="server">
<title>Accordion</title>
</
head>
<
body style="font: verdana">
<form id="form1" runat="server">
<asp:ScriptManager ID="scriptManager" runat="server" />
<div>
<ajaxToolkit:Accordion runat="server" ID="theAccordion" SelectedIndex="0" AutoSize="Limit" BackColor="LightCyan" FadeTransitions="true" TransitionDuration="333" FramesPerSecond="30" Width="275px" Height="205">
<Panes>
<ajaxToolkit:AccordionPane ID="AccordionPane1" runat="server">
<Header>
<table width="100%" cellpadding="0" cellspacing="0" style="border-bottom: 1px solid Navy; border-top: 1px solid Navy; border-left: 1px solid Navy; border-right: 1px solid Navy;">
<tr style="background: gray; font-size: larger;">
<td>
Models
</td>
</tr>
</table>
</Header>
<Content>
<div style="background: #336699">
<ul>
<li>Male Models</li>
<li>Female Models</li>
<li>Comments</li>
<li>Blogs</li>
<li>Contact to models</li>
</ul>
</div>
</Content>
</ajaxToolkit:AccordionPane>

<ajaxToolkit:AccordionPane ID="AccordionPane2" runat="server">
<Header>
<table width="100%" cellpadding="0" cellspacing="0" style="border-bottom: 1px solid Navy; border-top: 1px solid Navy; border-left: 1px solid Navy; border-right: 1px solid Navy;">
<tr style="background: gray; font-size: larger;">
<td>
Photographer
</td>
</tr>
</table>
</Header>
<Content>
<div style="background: #336699">
<ul>
<li>Men Photographer</li>
<li>Female Photographer</li>
<li>Comments</li>
<li>Blog</li>
<li>Send Email</li>
</ul>
</div>
</Content>
</ajaxToolkit:AccordionPane>

<ajaxToolkit:AccordionPane ID="AccordionPane3" runat="server">
<Header>
<table width="100%" cellpadding="0" cellspacing="0" style="border-bottom: 1px solid Navy; border-top: 1px solid Navy; border-left: 1px solid Navy; border-right: 1px solid Navy;">
<tr style="background: gray; font-size: larger;">
<td>
Agents
</td>
</tr>
</table>
</Header>
<Content>
<div style="background: #336699">
<ul>
<li>Agent's Models</li>
<li>Agent's Photographer</li>
<li>Agent's Comments</li>
<li>Blog</li>
<li>Contact To Agent</li>
</ul>
</div>
</Content>
</ajaxToolkit:AccordionPane>

<ajaxToolkit:AccordionPane ID="AccordionPane4" runat="server">
<Header>
<table width="100%" cellpadding="0" cellspacing="0" style="border-bottom: 1px solid Navy; border-top: 1px solid Navy; border-left: 1px solid Navy; border-right: 1px solid Navy;">
<tr style="background: gray; font-size: larger;">
<td>
HairStylist
</td>
</tr>
</table>
</Header>
<Content>
<div style="background: #336699">
<ul>
<li>Latest HairStyle</li>
<li>Modern HairStyle</li>
<li>Comments</li>
<li>Blog</li>
<li>Send Email</li>
</ul>
</div>
</Content>
</ajaxToolkit:AccordionPane>
</Panes>
</ajaxToolkit:Accordion>
</div>
</form>
</
body>
</
html>

Output:

If I set SelectedIndex="0" then by default content of first AccordionPane will be visible as follows-

Image1.JPG

Figure 1:

If I click on header of second AccordionPane (Photographer) then you will see something like this.

image2.JPG

Figure 2:

image3.JPG

Figure 3:

Here The Accordion control is used with four panes. The header for each pane shows the title and the content shows the track listings.

Login to add your contents and source code to this article
share this article :
post comment
 

thanks for the code.
very cool control, I already know where i'm going to add something like this :D

--------------------------------
Danny, Oakland Locksmith

Posted by danny dror Nov 23, 2009
Nevron Gauge for SharePoint
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor