title: C# How to access a dropdownbox in a listview?
body: <p>I have a listview. In my listview I have a dropdownbox which I want to fill in my codebehind page. Only the thing is, I don't know how to access this webcontrol. The following doesn't work:</p>
  
  <pre><code>DropDownList ddl = (DropDownList)lvUserOverview.Controls[0];
  </code></pre>
  
  <p>I know the index is 0 because the dropdownlist is the only control on the listview (also when I try index 1 I get a index out of range exception).</p>
  
  <p>Can someone tell me how i can access the dropdownlist? In my pagebehind I want to add listitems.</p>
  
  <p>ASPX Code :</p>
  
  <pre><code>&lt;asp:DropDownList ID="ddlRole" onload="ddlRole_Load" runat="server"&gt;
  &lt;/asp:DropDownList&gt;
  </code></pre>
  
  <p>Codebehind:</p>
  
  <pre><code>protected void ddlRole_Load(object sender, EventArgs e)
  {
    DropDownList ddl = (DropDownList)lvUserOverview.FindControl("ddlRole");
    if (ddl != null)
    {
        foreach (Role role in roles)
            ddl.Items.Add(new ListItem(role.Description, role.Id.ToString()));
    }
  }
  </code></pre>