ASP.NET dynamic checkbox or dropdownlist
<p>I have a gridview in an ASP.NET site.</p>

<p>There's a TemplateField right now that works fine - this is a survey form, and by default questions are answered using textboxes:</p>

<pre><code>&lt;asp:TemplateField HeaderText="" Visible="True" &gt;
   &lt;ItemTemplate&gt;
      &lt;asp:TextBox ID="txtAnswer" Text='&lt;%# Bind("Answer") %&gt;' runat="server" 
       TextMode="MultiLine" Height="76px" MaxLength="2000" Width="377px"&gt;
       &lt;/asp:TextBox&gt;
    &lt;/ItemTemplate&gt;
 &lt;EditItemTemplate&gt;
       &lt;asp:TextBox ID="txtAnswer" Text='&lt;%# Bind("Answer") %&gt;' runat="server" 
       TextMode="MultiLine" Height="76px" MaxLength="2000" Width="377px"&gt;
       &lt;/asp:TextBox&gt;
 &lt;/EditItemTemplate&gt;
 &lt;/asp:TemplateField&gt;
</code></pre>

<p>The requirement is to now add new questions that may be answered by dropdownlists. I've got an idea on how to do this (passing the question number into a function and checking for the presence of dropdown answers that are stored in another table), but I'm struggling with dynamically updating the templatefield based on the question type...any suggestions?</p>

<p><strong>UPDATE</strong></p>

<p>I managed to get this partially working through a helper function. (Probably not my best code, but it's almost getting the job done) The thing is I get a string that's telling me the type in my output instead of the actual controls (Textboxes or dropdownlists, respectively)...how can I correct that?</p>

<pre><code>  public Control GetAnswerControl(string QuestionID, string Answer)
{
    List&lt;ListItem&gt; lstOptions = new List&lt;ListItem&gt;();

    SqlCommand cmd = new SqlCommand("pDropDownAnswers_Get", functions.NewSupplierRequest);
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.Add("@QuestionID", SqlDbType.Int);
    cmd.Parameters["@QuestionID"].Value = Int32.Parse(QuestionID);

    try
    {
        functions.NewSupplierRequest.Open();
        SqlDataReader r = cmd.ExecuteReader();
        while (r.Read())
        {
            lstOptions.Add(new ListItem(r["DropDownAnswer"].ToString(), r["DropDownAnswer"].ToString()));
        }
    }
    catch (Exception err)
    {
        this.lblError.Text = err.Message;
    }
    finally
    {
        functions.NewSupplierRequest.Close();
    }

    if (lstOptions.Count == 0)
    {
        TextBox tb = new TextBox();
        tb.ID = "txtAnswer";
        tb.Text = Answer;
        tb.TextMode = TextBoxMode.MultiLine;
        tb.Height = 76;
        tb.Width = 377;
        tb.MaxLength = 2000;

        return tb;
    }
    else
    {
        DropDownList dl = new DropDownList();
        dl.DataSource = lstOptions;
        dl.DataBind();
        dl.SelectedValue = Answer;
        return dl;
    }
}
</code></pre>
