title: C# To Dynamically Generate HTML Table
body: <p>I am attempting to Dynamically generate an HTML Table.  What I am after is to have a header row and a second row of textboxes under the header row (all aligned horizontally across the page).  I attempted this syntax - however it ignores the values that are selected in the checkboxlist, and the textboxes for input are stacked on top of each other instead of horizontal.</p>
  
  <p>Can someone right the errors in my ways?</p>
  
  <pre><code>    protected void btnBullDozer_Click(object sender, EventArgs e)
  {
      StringBuilder sb = new StringBuilder(string.Empty);
      var columnname = string.Empty;
      foreach (System.Web.UI.WebControls.ListItem item in checkboxtest.Items)
      {
          columnname = item.Text;
  
          sb.Append("&lt;table&gt;");
          sb.Append("&lt;tr&gt;");
          sb.Append("&lt;th&gt;Sponsor Level&lt;/th&gt;");
          sb.Append("&lt;th&gt;" + item.Selected + "&lt;/th&gt;");
      }
      sb.Append("&lt;/tr&gt;");
      var cm = string.Empty;
      int z = 1;
      foreach (System.Web.UI.WebControls.ListItem item in checkboxtest.Items)
      {
          cm = item.Text;
          sb.Append("&lt;tr&gt;");
          sb.Append("&lt;td&gt;&lt;input type=\"text\" name=\"field " + z + "\"&gt;&lt;/td&gt;");
          z = z + 1;
      }
      sb.Append("&lt;/tr&gt;");
      sb.Append("&lt;/table&gt;");
  
      mask.InnerHtml = sb.ToString();
  }
  </code></pre>
  
  <p>Hypothetical of what my desired grid should look like - let's say that the user selected 4 options from the checkboxlist then I would want 5 headers (Sponsor Level, and the names selected) then one row with 5 empty textboxes underneath for the data entry</p>