title: Nested Control Accordion < Accordion < ListView ItemEditing Issue
body: <p>Got a question, and I'm quite baffled as to why it is not working. I have a ListView control nested within an AJAX Accordion, which is nested inside another AJAX Accordion.</p>
  <p>i.e. Accordion1 &lt; Accordion2 &lt; ListView</p>
  <p>All of these controls are databound in code-behind.</p>
  <p>I've currently implemented a method that allows me to edit the contents of any ListView, but this only works in the first pane of Accordion1. Every record, as long as it is in the first pane of Accordion1 can be edited without any problems.</p>
  <p>When I click my Edit button in the ListView when it is in any other pane of Accordion1, it does not change the ListView to the EditItemTemplate. I thought this might be a naming issue with the UniqueID assigned to the ListViews, but they are different (albeit not by much).</p>
  <blockquote>
  <p>((System.Web.UI.Control)(lSender)).UniqueID    &quot;ctl00$MainContent$ticketAccordion$acc_ticketTypeAccordion_Pane_0_content$acc_ticketAccord&gt;ion_Pane_0_content$LV_ticketDataListview&quot;    string</p>
  <p>((System.Web.UI.Control)(lSender)).UniqueID    &quot;ctl00$MainContent$ticketAccordion$acc_ticketTypeAccordion_Pane_1_content$acc_ticketAccord&gt;ion_Pane_0_content$LV_ticketDataListview&quot;    string</p>
  </blockquote>
  <p>Here is my code for the control:</p>
  <pre><code>&lt;%@ Control Language=&quot;C#&quot; AutoEventWireup=&quot;true&quot; CodeBehind=&quot;TicketAccordion.ascx.cs&quot; Inherits=&quot;GSWebApp.UserControls.TicketAccordion&quot; %&gt;
  
  &lt;ajaxToolkit:Accordion ID=&quot;acc_ticketTypeAccordion&quot; runat=&quot;server&quot; RequireOpenedPane=&quot;false&quot; OnItemDataBound=&quot;acc_ticketTypeAccordion_ItemDataBound&quot;&gt;
      &lt;HeaderTemplate&gt;
          &lt;asp:Label ID=&quot;Lbl_statName&quot; runat=&quot;server&quot; Text='&lt;%# Eval(&quot;StatName&quot;) %&gt;'&gt;&lt;/asp:Label&gt;
          &lt;asp:HiddenField ID=&quot;Hdn_statID&quot; runat=&quot;server&quot; Value='&lt;%# Eval(&quot;StatID&quot;) %&gt;' /&gt;
          &lt;asp:Label ID=&quot;Lbl_statCount&quot; runat=&quot;server&quot;&gt;&lt;/asp:Label&gt;
      &lt;/HeaderTemplate&gt;
      &lt;ContentTemplate&gt;
  
          &lt;asp:HiddenField ID=&quot;Hdn_statID&quot; runat=&quot;server&quot; Value='&lt;%# Eval(&quot;StatID&quot;) %&gt;' /&gt;
          &lt;ajaxToolkit:Accordion ID=&quot;acc_ticketAccordion&quot; runat=&quot;server&quot; RequireOpenedPane=&quot;false&quot; OnItemDataBound=&quot;ticketAccordion_ItemDataBound&quot;&gt;
              &lt;HeaderTemplate&gt;
                  &lt;table class=&quot;TicketAccordionTable&quot;&gt;
                      &lt;tr&gt;
                          &lt;td class=&quot;FLoatLeft&quot;&gt;
                              &lt;asp:Label ID=&quot;Lbl_ticketID&quot; runat=&quot;server&quot; Text='&lt;%# &quot;Ticket Ref# &quot; + Eval(&quot;SupportTicketID&quot;) + &quot; - &quot; %&gt;' CssClass=&quot;TLabel&quot;&gt;&lt;/asp:Label&gt;
                              &lt;asp:Label ID=&quot;Lbl_ticketSumm&quot; runat=&quot;server&quot; Text='&lt;%# Eval(&quot;SupportSummary&quot;) %&gt;' CssClass=&quot;TLabel&quot;&gt;&lt;/asp:Label&gt;
                          &lt;/td&gt;
                          &lt;td class=&quot;FloatRight&quot;&gt;
                              &lt;asp:Label ID=&quot;Lbl_ticketDateLog&quot; runat=&quot;server&quot; Text='&lt;%# Eval(&quot;DateLogged&quot;, &quot;{0:dd/MM/yy HH:mm:ss}&quot;) %&gt;' CssClass=&quot;TLabel&quot;&gt;&lt;/asp:Label&gt;
                          &lt;/td&gt;
                      &lt;/tr&gt;
                  &lt;/table&gt;
              &lt;/HeaderTemplate&gt;
              &lt;ContentTemplate&gt;
                  &lt;asp:UpdatePanel ID=&quot;UpdPnl_ticketData2&quot; runat=&quot;server&quot; UpdateMode=&quot;Conditional&quot; ChildrenAsTriggers=&quot;true&quot;&gt;
                      &lt;ContentTemplate&gt;
                          &lt;asp:HiddenField ID=&quot;Hdn_supportTicketID&quot; runat=&quot;server&quot; Value='&lt;%# Eval(&quot;SupportTicketID&quot;) %&gt;' /&gt;
                          &lt;asp:ListView ID=&quot;LV_ticketDataListview&quot; runat=&quot;server&quot; DataKeyNames=&quot;SupportTicketID&quot; ItemPlaceholderID=&quot;itemPlaceholder&quot;
                              OnItemEditing=&quot;LV_ticketDataListview_ItemEditing&quot;
                              OnItemCanceling=&quot;LV_ticketDataListview_ItemCanceling&quot;
                              OnItemInserting=&quot;LV_ticketDataListview_ItemInserting&quot;
                              OnItemUpdating=&quot;LV_ticketDataListview_ItemUpdating&quot;
                              OnItemDeleting=&quot;LV_ticketDataListview_ItemDeleting&quot;&gt;
                              &lt;LayoutTemplate&gt;
                                  &lt;table class=&quot;TicketListViewTable&quot;&gt;
                                      &lt;asp:PlaceHolder ID=&quot;itemPlaceholder&quot; runat=&quot;server&quot;&gt;&lt;/asp:PlaceHolder&gt;
                                  &lt;/table&gt;
                                  &lt;footer&gt;
                                      &lt;asp:Button ID=&quot;Btn_editTicketData&quot; runat=&quot;server&quot; Text=&quot;New Reply&quot; CssClass=&quot;TLVButton&quot; OnClick=&quot;Btn_editTicketData_Click&quot; /&gt;
                                      &lt;asp:Button ID=&quot;Btn_deleteTicketData&quot; runat=&quot;server&quot; CommandName=&quot;Delete&quot; Text=&quot;Delete Ticket&quot; OnClientClick=&quot;if(!confirm('Are you sure you want to delete this ticket?')) return false;&quot; CssClass=&quot;TLVButton&quot; /&gt;
                                  &lt;/footer&gt;
                              &lt;/LayoutTemplate&gt;
                              &lt;ItemTemplate&gt;
                                  &lt;tr&gt;
                                      &lt;td&gt;
                                          &lt;asp:Label ID=&quot;Lbl_LV_ticketLog&quot; runat=&quot;server&quot; Text='&lt;%# &quot;Logged By: &quot; + Eval(&quot;LoggedByEmployeeName&quot;) + &quot; - &quot; + Eval(&quot;TimeStamp&quot;) %&gt;' CssClass=&quot;TLabelLog&quot;&gt;&lt;/asp:Label&gt;&lt;/td&gt;
                                  &lt;/tr&gt;
                                  &lt;tr&gt;
                                      &lt;td&gt;
                                          &lt;asp:Label ID=&quot;Lbl_LV_ticketMessage&quot; runat=&quot;server&quot; Text='&lt;%# Eval(&quot;MessageLog&quot;) %&gt;' CssClass=&quot;TLabel&quot;&gt;&lt;/asp:Label&gt;
                                      &lt;/td&gt;
                                  &lt;/tr&gt;
                                  &lt;tr&gt;
                                      &lt;td&gt;
                                          &lt;asp:Button ID=&quot;Btn_editTicketData&quot; runat=&quot;server&quot; CommandName=&quot;Edit&quot; CommandArgument='&lt;%# Eval(&quot;SupportTicketID&quot;) %&gt;' Text=&quot;Edit&quot; CssClass=&quot;TLVButton&quot; /&gt;
                                          &lt;asp:Button ID=&quot;Btn_deleteTicketData&quot; runat=&quot;server&quot; CommandName=&quot;Delete&quot; Text=&quot;Delete&quot; CssClass=&quot;TLVButton&quot; /&gt;
                                      &lt;/td&gt;
                                  &lt;/tr&gt;
                              &lt;/ItemTemplate&gt;
                              &lt;EditItemTemplate&gt;
                                  &lt;asp:HiddenField ID=&quot;Hdn_supportTicketDataID&quot; runat=&quot;server&quot; Value='&lt;%# Eval(&quot;SupportTicketDataID&quot;) %&gt;' /&gt;
                                  &lt;tr&gt;
                                      &lt;td&gt;
                                          &lt;asp:Label ID=&quot;Lbl_LV_ticketLog&quot; runat=&quot;server&quot; Text='&lt;%# &quot;Logged By: &quot; + Eval(&quot;LoggedByEmployeeName&quot;) + &quot; - &quot; + Eval(&quot;TimeStamp&quot;) %&gt;' CssClass=&quot;TLabelLog&quot;&gt;&lt;/asp:Label&gt;&lt;/td&gt;
                                  &lt;/tr&gt;
                                  &lt;tr&gt;
                                      &lt;td&gt;
                                          &lt;asp:TextBox ID=&quot;Tb_LV_ticketMessage&quot; runat=&quot;server&quot; Text='&lt;%# Eval(&quot;MessageLog&quot;) %&gt;' CssClass=&quot;TLabel&quot;&gt;&lt;/asp:TextBox&gt;
                                      &lt;/td&gt;
                                  &lt;/tr&gt;
                                  &lt;tr&gt;
                                      &lt;td&gt;
                                          &lt;asp:Button ID=&quot;Btn_saveTicketData&quot; runat=&quot;server&quot; CommandName=&quot;Update&quot; Text=&quot;Save&quot; CssClass=&quot;TLVButton&quot; /&gt;
                                          &lt;asp:Button ID=&quot;Btn_cancelTicketData&quot; runat=&quot;server&quot; CommandName=&quot;Cancel&quot; Text=&quot;Cancel&quot; CssClass=&quot;TLVButton&quot; /&gt;
                                      &lt;/td&gt;
                                  &lt;/tr&gt;
                              &lt;/EditItemTemplate&gt;
                              &lt;InsertItemTemplate&gt;
                                  &lt;tr&gt;
                                      &lt;td&gt;
                                          &lt;asp:TextBox ID=&quot;Tb_LV_ticketMessage&quot; runat=&quot;server&quot; CssClass=&quot;TLabel&quot;&gt;&lt;/asp:TextBox&gt;
                                      &lt;/td&gt;
                                  &lt;/tr&gt;
                                  &lt;tr&gt;
                                      &lt;td&gt;
                                          &lt;asp:Button ID=&quot;Btn_saveTicketData&quot; runat=&quot;server&quot; CommandName=&quot;Insert&quot; Text=&quot;Save&quot; CssClass=&quot;TLVButton&quot; /&gt;
                                          &lt;asp:Button ID=&quot;Btn_cancelTicketData&quot; runat=&quot;server&quot; CommandName=&quot;Cancel&quot; Text=&quot;Cancel&quot; CssClass=&quot;TLVButton&quot; /&gt;
                                      &lt;/td&gt;
                                  &lt;/tr&gt;
                              &lt;/InsertItemTemplate&gt;
                              &lt;ItemSeparatorTemplate&gt;
                              &lt;/ItemSeparatorTemplate&gt;
                          &lt;/asp:ListView&gt;
                      &lt;/ContentTemplate&gt;
                  &lt;/asp:UpdatePanel&gt;
              &lt;/ContentTemplate&gt;
          &lt;/ajaxToolkit:Accordion&gt;
      &lt;/ContentTemplate&gt;
  &lt;/ajaxToolkit:Accordion&gt;
  </code></pre>
  <p>And here is my code-behind:</p>
  <pre><code>public partial class TicketAccordion : System.Web.UI.UserControl
      {
          GSWIISAService.GSWebServiceClient serviceClient;
          List&lt;SupportTicket&gt; ticketHoldList;
          List&lt;SupportTicketData&gt; ticketDataHoldList;
  
          protected void Page_Load(object sender, EventArgs e)
          {
              serviceClient = new GSWIISAService.GSWebServiceClient();
              BindLists(1006);
              BindAccTicketAccordion();
          }
  
          private void BindLists(int _clientRef)
          {
              ticketHoldList = serviceClient.GetSupportTicketsByReference(_clientRef).ToList();
              ticketDataHoldList = serviceClient.GetSupportTicketDataByRefID(_clientRef).ToList();
          }
  
          private void BindAccTicketAccordion()
          {
              acc_ticketTypeAccordion.DataSource = (from c in ticketHoldList select new { StatID = c.StatusID, StatName = c.Status }).Distinct().ToList();
              acc_ticketTypeAccordion.DataBind();
          }
  
          protected void ticketAccordion_ItemDataBound(object sender, AccordionItemEventArgs e)
          {
              if (e.ItemType == AccordionItemType.Content)
              {
                  HiddenField hdnID = (HiddenField)e.AccordionItem.FindControl(&quot;Hdn_supportTicketID&quot;);
                  int ID = int.Parse(hdnID.Value);
                  ListView ticketListview = (ListView)e.AccordionItem.FindControl(&quot;LV_ticketDataListview&quot;);
                  ticketListview.DataSource = ticketDataHoldList.Where(p =&gt; p.SupportTicketID == ID);
                  ticketListview.DataBind();
              }
          }
  
          protected void acc_ticketTypeAccordion_ItemDataBound(object sender, AccordionItemEventArgs e)
          {
              if (e.ItemType == AccordionItemType.Header)
              {
                  HiddenField hdnStatID = (HiddenField)e.AccordionItem.FindControl(&quot;Hdn_statID&quot;);
                  int statID = int.Parse(hdnStatID.Value);
                  Label statCount = (Label)e.AccordionItem.FindControl(&quot;Lbl_statCount&quot;);
                  statCount.Text = &quot; (&quot; + ticketHoldList.Where(p =&gt; p.StatusID == statID).Count().ToString() + &quot;)&quot;;
              }
              if (e.ItemType == AccordionItemType.Content)
              {
                  HiddenField hdnStatID = (HiddenField)e.AccordionItem.FindControl(&quot;Hdn_statID&quot;);
                  int statID = int.Parse(hdnStatID.Value);
                  Accordion accTicketAccordion = (Accordion)e.AccordionItem.FindControl(&quot;acc_ticketAccordion&quot;);
                  accTicketAccordion.DataSource = ticketHoldList.Where(p =&gt; p.StatusID == statID);
                  accTicketAccordion.DataBind();             
              }
          }
  
          protected void LV_ticketDataListview_ItemEditing(object sender, ListViewEditEventArgs e)
          {        
              ListView lSender = (ListView)sender;
              lSender.EditIndex = e.NewEditIndex;
              HiddenField hdnSupportTicketID = (HiddenField)lSender.Parent.FindControl(&quot;Hdn_supportTicketID&quot;);
              lSender.DataSource = ticketDataHoldList.Where(p =&gt; p.SupportTicketID == int.Parse(hdnSupportTicketID.Value));
              lSender.DataBind();
          }
  
          protected void LV_ticketDataListview_ItemCanceling(object sender, ListViewCancelEventArgs e)
          {
              ListView lSender = (ListView)sender;
              lSender.EditIndex = -1;
              lSender.InsertItemPosition = InsertItemPosition.None;
              lSender.DataBind();
          }
  
          protected void LV_ticketDataListview_ItemInserting(object sender, ListViewInsertEventArgs e)
          {
  
          }
  
          protected void LV_ticketDataListview_ItemUpdating(object sender, ListViewUpdateEventArgs e)
          {
              ListView lSender = (ListView)sender;
              HiddenField hdnSupportTicketDataID = (HiddenField)lSender.Items[e.ItemIndex].FindControl(&quot;Hdn_supportTicketDataID&quot;);
              TextBox tbMessage = (TextBox)lSender.Items[e.ItemIndex].FindControl(&quot;Tb_LV_ticketMessage&quot;);
              
              SupportTicketDataEntity entity = new SupportTicketDataEntity();
              int stDataID = int.Parse(hdnSupportTicketDataID.Value);
              entity.SupportTicketDataID = stDataID;
              entity.MessageLog = tbMessage.Text;
              entity.Edited = true;
              //entity.EditedByID = Page.User.Identity.Name;
              entity.EditTimeStamp = DateTime.Now;
  
              serviceClient.UpdateSupportTicketData(entity);
              BindLists(1006);
              BindAccTicketAccordion();
              //lSender.DataBind();
          }
  
          protected void LV_ticketDataListview_ItemDeleting(object sender, ListViewDeleteEventArgs e)
          {
  
          }
  
          protected void Btn_editTicketData_Click(object sender, EventArgs e)
          {
              Button bSender = (Button)sender;
              ListView bSenderListview = (ListView)bSender.Parent.Parent;
              bSenderListview.InsertItemPosition = InsertItemPosition.LastItem;
              
              BindAccTicketAccordion();
          }
  </code></pre>