title: Finding drop down list control from a stored procedure in edit item template of gridview in asp.net c#
body: <p>I am trying to find a DropDownList control on the EditItemTemplate of a grid view, to populate it with results from a query before it is drawn, but the control is never found.</p>
  
  <pre><code>ddlParent == null
  </code></pre>
  
  <p>Always!</p>
  
  <p>I may be missing something very obvious but i have tried about 8 different methods to get this find control working, but no matter what i do, it comes up null.</p>
  
  <p>I have included both the ASP and the C#, the sql should not be important as i cant even reach the call!</p>
  
  <p>ASP:</p>
  
  <pre><code>            &lt;asp:TemplateField SortExpression="LocationArea2.Name" HeaderText="Parent Location Area"&gt;
                  &lt;ItemTemplate&gt;
                      &lt;asp:Label runat="server" Text='&lt;%# Eval("LocationArea2.Name") %&gt;' /&gt;
                  &lt;/ItemTemplate&gt;
                  &lt;EditItemTemplate&gt;
                      &lt;asp:DropDownList ID="ddlParent" runat="server" AppendDataBoundItems="true" DataTextField="LocationArea2.Name"
                          DataValueField="ParentID" AutoPostBack="false" SelectedValue='&lt;%# Bind("ParentID") %&gt;'&gt;
                      &lt;/asp:DropDownList&gt;
                  &lt;/EditItemTemplate&gt;
              &lt;/asp:TemplateField&gt;
  </code></pre>
  
  <p>C#:</p>
  
  <pre><code>protected void gvLocationArea_RowDataBound(object sender, GridViewRowEventArgs e)
      {
          if (gvLocationArea.EditIndex == e.Row.RowIndex)
          {
              DropDownList ddlParent = (DropDownList)gvLocationArea.Rows[gvLocationArea.EditIndex].FindControl("ddlParent");
              if (ddlParent != null)
              {
                  using (SalesSQLEntities db = new SalesSQLEntities())
                  {
                      ddlParent.DataSource = db.GetRecursiveAreaList(Convert.ToInt32(((TextBox)gvLocationArea.Rows[gvLocationArea.EditIndex].FindControl("txtLocationAreaID")).Text), true);
                      ddlParent.DataBind();
                      ddlParent.Items.Add(new ListItem("* None", ""));
                  }
              }
          }
      }
  </code></pre>
  
  <p>I know there is something missing here, the control is just never found no matter what i've tried!</p>