Refrencing dynamically created ASP.NET DDL inside a dynamically created ASP.NET table - how to do it?
<p>I have a table that I create programatically from my <code>CreateChildControls()</code> function of ASP.NET project. During creation of the table, I add drop down list to each row. Code is below: </p>

<pre><code>protected override void CreateChildControls()
{

SPWeb web = SPContext.Current.Web;
Table table = new Table();
allChecks = new CheckBox[nrOfModules];
allDropDowns = new DropDownList[nrOfModules];

int i=0;

foreach (SPList list in web.Lists)
{
    TableRow tr = new TableRow();
    TableCell tc1 = new TableCell();

    tc1.Controls.Add(new LiteralControl(String.Format("{0}", list.Title)));
    tr.Cells.Add(tc1);
    TableCell tc2 = new TableCell();
    allChecks[i] = new CheckBox() { ID = string.Format("CheckBox_{0}",i), AutoPostBack = true };
    allChecks[i].CheckedChanged += new EventHandler(checkBox_CheckedChanged);
    tc2.Controls.Add(allChecks[i]);
    tr.Cells.Add(tc2);

    TableCell tc3 = new TableCell();
    allDropDowns[i] = new DropDownList();

    for (int kk = 0; kk &lt; nrOfModules+1; kk++)
    {
         if (kk == 0)
               allDropDowns[i].Items.Add("");
         else
               allDropDowns[i].Items.Add((kk).ToString());
    }

    allDropDowns[i].ID = string.Format("DropDownList_{0}",i);

    allDropDowns[i].Enabled = false;
    allDropDowns[i].SelectedIndex = 0;
    allDropDowns[i].SelectedIndexChanged += new EventHandler(ddl_SelectedIndexChanged);
    tc3.Controls.Add(allDropDowns[i]);
    tr.Cells.Add(tc3);

    table.Rows.Add(tr);
    i++;
}}
</code></pre>

<p>Now in the eventhandler method named <code>checkBox_CheckedChanged</code> I enable my dropdown that is in the same row as a checkbox on which the user clicked. Here is the code:</p>

<pre><code>void checkBox_CheckedChanged(object sender, EventArgs e)
{
    CheckBox checkBox = sender as CheckBox;
    string ddl_ID = checkBox.ID.Replace("CheckBox", "DropDownList");
    DropDownList ddl = Parent.Page.FindControl(ddl_ID) as DropDownList;
    if (ddl != null)
        ddl.Enabled = checkBox.Checked;
}
</code></pre>

<p>I have tried with <code>this</code> reference instead of <code>Parent</code> but nothing helps. The DropDownList reference is always null.</p>

<p>I have read that dynamically created controls have some problems with FindControl method because they are not available at the moment of <code>FindControl</code> usage. Is there any article how to make this DropDownList not null?</p>
