title: How to create table dynamically in c#
body: <pre><code>&lt;table id="tableContent" border="1" runat="server"&gt;
      &lt;tr&gt;
          &lt;td colspan="3"&gt;
          Record 1
          &lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;1&lt;/td&gt;
          &lt;td&gt;2&lt;/td&gt;
          &lt;td&gt;3&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;a&lt;/td&gt;
          &lt;td&gt;b&lt;/td&gt;
          &lt;td&gt;c&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;m&lt;/td&gt;
          &lt;td&gt;n&lt;/td&gt;
          &lt;td&gt;o&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td colspan="3"&gt;
              &lt;input id="Button1" type="button" value="button" /&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>I have to create above table dynamically in c#
  I am trying but didnt get</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
  {
  
      HtmlTableRow row = null;
      HtmlTableCell cell = null;
  
      for(int i = 0; i &lt; 5; i++)
      {
          row = new HtmlTableRow();
          cell = new HtmlTableCell();
          tableContent.Controls.AddAt(i, row);
          row.Controls.AddAt(i, cell);
          cell.InnerText="1";
      }
  }
  </code></pre>