title: How can I access my dropdownlist control within my DataGrid?
body: <p>I have a DataGrid control (NOT GridView) that has 4 columns. One of the columns is a DropDownList. What I'm trying to do is access the DropDownList control from my dgTicket_ItemDataBound(.....) process and I'm having no success.</p>
  
  <p>I've researched and tried several different ways with no success.</p>
  
  <p>This is what I have:</p>
  
  <pre><code>protected void dgPrintTicket_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
  {
        string SQL1 = @"SELECT Machine_Id FROM SFD00006 WHERE WC_Id = '" + wc + "'";
  
        DropDownList ddl = (DropDownList)e.Item.Cells[2].FindControl("ddlMachId");
  
        string val = ((DropDownList)dgPrintTicket.SelectedItem.Cells[2].FindControl("ddlMachId")).Text;
  
        if (ddl != null)
        {                    
            ddl.DataSource = Lib.getArrayList(SQL1);
            ddl.SelectedValue = val;
            ddl.DataBind();
        }
  }
  </code></pre>
  
  <p>I want to access the DropDownList and populate it with all the Machine codes that I get from my select statement but my ddl keeps coming back as null.</p>
  
  <p>Any help would be greatly appreciated.</p>
  
  <p>thank you all.</p>
  
  <p>Sam</p>