问题描述:

Using .NET 3.5.

How do I programmtically expand/collapse the panes contained within a AJAX accordion control?

My page will have several accordions controls which I want to be able to mass expand/collapse with some buttons.

UPDATE1

My final code solution looks like this:

<script language="javascript">

function collapse_all(flag)

{

if(flag==true)

{

var behavior = $get("<%=Accordion1.ClientID%>").AccordionBehavior;

behavior.set_SelectedIndex(-1);

}

else

{

var behavior = $get("<%=Accordion1.ClientID%>").AccordionBehavior;

behavior.set_SelectedIndex(0);

}

}

</script>

网友答案:

you can find the accourdion control in javascript and call "set_SelectedIndex(-1)"

so (using jquery)

$("#<%=Accordion1.ClientID%>_AccordionExtender").set_SelectedIndex(-1)

if you have a few, you can either do them all discretly or use one of the jquery selectors to find them all, the accordions will have to have been set up to allow all panes to close i believe (RequireOpenedPane = false)

网友答案:

You can't expand them programmatically via you server-side code(VB.NET/C#) because the expansion of the panes is done in the client-side code(JavaScript). If I were you I'd suggest taking a look at the JQuery Libraries and using their show/hide functions to build a custom accordion control to do what you want. JQuery will seem less "WebForm-like" but you'll find it much more flexible than the AJAX Control Toolkit.

网友答案:

If you put the accordion control in an asp.net ajax update panel, you can collapse all panes easily via the codebehind setting the selected index to zero.

相关阅读:
Top