title: Accessing controls in the edititemtemplate of a listview
body: <p>I am working with the listview control. By default I am showing the itemtemplate with an edit button. When the edit button is pressed the listview switches to the edititemtemplate. I need to populate one of the controls in the edititemtemplate based on the item being edited - I've tried accessing the control (via FindControl) in the ItemEditing event (and pretty much every other event as well), however the controls just don't seem to exist. I can access controls in the itemtemplate ok, but not the edititemtemplate.</p>
  
  <p>Can anyone let me know how I can access a control held within the edititemtemplate of a listview, and from which event I should do so?</p>
  
  <p><strong>EDIT</strong>
  I'm trying to access the control using this:</p>
  
  <pre><code>protected void UnitsLV_ItemEditing(object sender, ListViewEditEventArgs e)
  {
      ListViewItem item = UnitsLV.Items[e.NewEditIndex];
      ListBox tempLB = (ListBox)e.item.FindControl("ListBox3");
  }
  </code></pre>
  
  <p>I've also tried in ItemDataBound and ItemCreated.</p>
  
  <p>The listview declaration is:</p>
  
  <pre><code>&lt;asp:Content ID="Content1" ContentPlaceHolderID="ColumnA" runat="server"&gt;
      &lt;asp:Panel ID="Panel1" runat="server"&gt;
          &lt;asp:UpdatePanel ID="UpdatePanel1" runat="server"&gt;
              &lt;ContentTemplate&gt;
                  &lt;asp:Panel ID="SummaryPnl" runat="server"&gt;
                      &lt;asp:ListView ID="UnitsLV" runat="server" DataSourceID="DataLDS" DataKeyNames="u_uid"
                          InsertItemPosition="LastItem" OnItemInserting="UnitsLV_ItemInserting" OnItemDataBound="UnitsLV_ItemDataBound"
                          OnItemCreated="UnitsLV_ItemCreated" onitemediting="UnitsLV_ItemEditing"&gt;
                          &lt;ItemTemplate&gt;
                              &lt;tr class="rowA"&gt;
                                  &lt;td&gt;
                                      &lt;asp:Label runat="server" ID="UnitIDLbl" Text='&lt;%# Eval("u_uid")%&gt;'&gt;&lt;/asp:Label&gt;
                                  &lt;/td&gt;
                                  &lt;td&gt;
                                      &lt;%# Eval("u_Title")%&gt;
                                  &lt;/td&gt;
                                  &lt;td&gt;
                                      &lt;asp:LinkButton ID="EditBtn" runat="server" CommandName="Edit" CommandArgument='&lt;%#Eval("u_uid") %&gt;'
                                      Text="Edit" /&gt;
                                  &lt;/td&gt;
                                  &lt;td&gt;
                                      &lt;asp:LinkButton ID="DeleteBtn" runat="server" CommandName="Delete" CommandArgument='&lt;%#Eval("u_uid") %&gt;'
                                      Text="Delete" /&gt;
                                  &lt;/td&gt;
                              &lt;/tr&gt;
                          &lt;/ItemTemplate&gt;
                          &lt;InsertItemTemplate&gt;
                              &lt;tr class="rowB"&gt;
                                  &lt;td&gt;
                                      &lt;br /&gt;
                                      &amp;nbsp;
                                  &lt;/td&gt;
                                  &lt;td&gt;
                                      &lt;br /&gt;
                                      &lt;asp:TextBox ID="TitleTB" runat="server" Text='&lt;% #Bind("u_Title")%&gt;'&gt;&lt;/asp:TextBox&gt;
                                  &lt;/td&gt;
                                  &lt;td&gt;
                                      &lt;br /&gt;
                                      &lt;asp:ListBox ID="ListBox3" runat="server"&gt;&lt;/asp:ListBox&gt;
                                      &lt;asp:ListBox ID="ToBeDeletedLB" runat="server"&gt;&lt;/asp:ListBox&gt;
                                  &lt;/td&gt;
                                  &lt;td&gt;
                                      &lt;asp:LinkButton ID="InsertBtn" runat="server" CommandName="Insert" Text="Insert" /&gt;
                                  &lt;/td&gt;
                                  &lt;td&gt;
                                      &lt;asp:LinkButton ID="CancelBtn" runat="server" CommandName="Cancel" Text="Cancel" /&gt;
                                  &lt;/td&gt;
                              &lt;/tr&gt;
                          &lt;/InsertItemTemplate&gt;
                          &lt;EditItemTemplate&gt;
                              &lt;tr class="rowB"&gt;
                                  &lt;td&gt;
                                      &lt;br /&gt;
                                      &lt;asp:Label runat="server" ID="UnitIDLbl" Text='&lt;%# Bind("u_uid")%&gt;'&gt;&lt;/asp:Label&gt;
                                  &lt;/td&gt;
                                  &lt;td&gt;
                                      &lt;br /&gt;
                                      &lt;asp:TextBox ID="TitleTB" runat="server" Text='&lt;% #Bind("u_Title")%&gt;'&gt;&lt;/asp:TextBox&gt;
                                  &lt;/td&gt;
                                  &lt;td&gt;
                                      &lt;br /&gt;
                                      &lt;asp:ListBox ID="ListBox3" runat="server"&gt;&lt;/asp:ListBox&gt;
                                      &lt;asp:ListBox ID="ToBeDeletedLB" runat="server"&gt;&lt;/asp:ListBox&gt;
                                  &lt;/td&gt;
                                  &lt;td&gt;
                                      &lt;asp:LinkButton ID="UpdateBtn" runat="server" CommandName="Update" Text="Update" /&gt;
                                  &lt;/td&gt;
                                  &lt;td&gt;
                                      &lt;asp:LinkButton ID="LinkButton2" runat="server" CommandName="Cancel" Text="Cancel" /&gt;
                                  &lt;/td&gt;
                              &lt;/tr&gt;
                          &lt;/EditItemTemplate&gt;
                          &lt;LayoutTemplate&gt;
                              &lt;table id="Table2" runat="server" width="100%"&gt;
                                  &lt;tr id="Tr1" runat="server"&gt;
                                      &lt;td id="Td1" runat="server"&gt;
                                          &lt;table id="itemPlaceholderContainer" runat="server" border="0" style="" width="100%"&gt;
                                              &lt;tr id="itemPlaceholder" runat="server"&gt;&lt;/tr&gt;
                                          &lt;/table&gt;
                                      &lt;/td&gt;
                                  &lt;/tr&gt;
                                  &lt;tr id="Tr2" runat="server"&gt;
                                      &lt;td id="Td2" runat="server" style=""&gt;&lt;/td&gt;
                                  &lt;/tr&gt;
                              &lt;/table&gt;
                          &lt;/LayoutTemplate&gt;
                      &lt;/asp:ListView&gt;
                  &lt;/asp:Panel&gt;
              &lt;/ContentTemplate&gt;
          &lt;/asp:UpdatePanel&gt;
      &lt;/asp:Panel&gt;
  &lt;/asp:Content&gt;
  </code></pre>
  
  <p><strong>EDIT:</strong>
  I've iterated over all the controls in the listview using code similar to below, and the control is still not visible. Does the ItemEditing event fire before the edit template is shown? If so, what event can I use to access the edit template controls?</p>
  
  <pre><code>foreach (Control child in control.Controls)
  {
     Control result = Find(child, id);
     if (result != null)
     {
        return result;
     }
  }
  </code></pre>
  
  <p>**EDIT: **
  I can access the controls in the edititemtemplate in the listview's ItemCreated event, however none they have no content (I'd assume the data hasn't been bound yet), so I can't get the key-value I need to do a lookup to get the data I need to populate the control.</p>