Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Apr 27, 2009 05:28 AM by Vince Xu - MSFT
Apr 19, 2009 11:13 AM|LINK
Hi, I am having a UpdatePanel inside which I have placed a button and an Accordion control. When the button is clicked it is fetching some data from database and the records are being displayed in Accordion as different panes. Among these results is an
ImageButton (with different image in every pane) for which I want to write a click event. When I click this image button it should display some other results inside a second Accordion control which is inside the first one. But this event is not working -
I mean that in debug mode I am able to see that the event is firing and the results are being fetched, but they are not being displayed in the second accordion. I am not clear where I am going wrong.
Can anyone tell me how to write events for dynamically generated buttons/imagebuttons inside an accordion?
Thanks in advance..
dynamically created button in accordion
button click inside accordion
accordion inside accordion
Apr 19, 2009 04:52 PM|LINK
Since, you embedded the second accordion inside the first accordion, you need to take special care to get hold of the second accordion. In ASP.Net, the naming containers can contain other controls, but those controls are not directly accessible from the
codebehind. And Accordion controls are naming containers.
I assume you have two accordions, ParentAccordion and ChildAccordion, where child is nested within the parent.
With this setup, you need to use the following method:-
to get the instance of ChildAccordion. Then you can of course set the dynamic content.
I assume, you are already firing the event rightly as you said you could debug. This solution should work for you.
Apr 19, 2009 05:12 PM|LINK
Thanks for the reply.. I'll try that.
One more thing is that I need to get the selected item from the given accordion pane.I am able to go into the button click event if the ImageButton is same in all the panels. But for my requirement, I have different Image buttons depending on each record.Suppose
for a record with RecID =1, I have one image and for RecID=2 I have another image. These records are displayed in different panes in Accordion.
If I click the first ImageButton which is in first pane, I should get records from a child table whose RecID=1 (the field RecID is foreign key in the child table) and display them in child accordion. So my doubt is, how to capture the selected item, so that
I can recognise which ImageButton raised the event. Also, one more thing is that I wanted to place the ImageButton and the child accordion in an update panel. I am not sure whether that is the right thing to do or not. Please guide me with some code regarding
this. I am new to AJAX. Thanks a lot.
Apr 21, 2009 09:41 AM|LINK
Anybody there to help???
Apr 22, 2009 07:57 AM|LINK
You can build command bubble event for the button in Accordion. The row index you can assign to command argument of the button.
You can check this post http://forums.asp.net/t/1222400.aspx
It is about gridview, but they are the same thing on this question.
Apr 24, 2009 05:36 PM|LINK
But for Gridview there are rowdatabound and rowcommand events. In which event should I write the code for accordion? And can you help me with a few lines of code? Also I want to display the results in a second accordion which is inside the first. I have
tried with findcontrol() but I am not able to understand how to do it. Any ideas?
Apr 27, 2009 05:28 AM|LINK
You can use OnItemCommand and OnItemDataBound instead.
Please check the below sample:
<ajaxToolkit:Accordion ID="LinksAcc" FadeTransitions="true" RequireOpenedPane="false" ContentCssClass="acc-content"
CssClass="acc" HeaderSelectedCssClass="acc-selected-header" HeaderCssClass="acc-header" OnItemCommand="LinksAcc_ItemCommand" OnItemDataBound="LinksAcc_ItemDataBound"
TransitionDuration="150" DataSourceID="SqlDataSource1" runat="server">
<h5><asp:Label runat="server" ID="label1" Text='<%#Eval("Name")%>'></asp:Label></h5>
<asp:Button runat="server" ID="Button1" Text="button" CommandName='display'/>
protected void LinksAcc_ItemDataBound(object sender, AccordionItemEventArgs e)
if (e.AccordionItem.ItemType == AccordionItemType.Content)
Button bu = ((Button)e.AccordionItem.Controls);// you should check the location of your button
bu.CommandArgument = e.AccordionItem.DataItemIndex.ToString();
protected void LinksAcc_ItemCommand(object sender, CommandEventArgs e)
if (e.CommandName == "display")
index = Convert.ToInt32(e.CommandArgument); // The index of Button you clicking.