title: Creating a dynamic table for .NET code-behind C#
body: <p>I'm having trouble creating a table and putting data pulled from SQL into it. My solution at the moment is to create a table in Default.aspx, and then create the rows and cells in the C# code. </p>
  
  <p>My aspx code:</p>
  
  <pre><code>&lt;asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"&gt;
      &lt;h2&gt;
          Select a topic to view.
      &lt;/h2&gt;
      &lt;asp:Table ID="solutions" runat="server" Width="100%"&gt;
      &lt;/asp:Table&gt;
  &lt;/asp:Content&gt;
  </code></pre>
  
  <p>And where all the action should, but doesn't happen: 
  C#</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  using HtmlAgilityPack;
  using System.Data.SqlClient;
  
  namespace WebApplication1
  {
      public partial class _Default : System.Web.UI.Page
      {
          protected void Page_Load(object sender, EventArgs e)
          {
              SqlConnection anca = new System.Data.SqlClient.SqlConnection();
              anca.ConnectionString = "Data Source=anca;Initial Catalog=servicedesk;
              anca.Open();
  
              SqlCommand sub = new SqlCommand("SELECT TITLE FROM dbo.Solution", anca);
              SqlDataReader sReader = sub.ExecuteReader();
              List&lt;String&gt; subject = new List&lt;string&gt;();
              int solCount = 0;
              while (sReader.Read())
              {
                  subject.Add(sReader.ToString());
                  solCount++;
              }
              sReader.Close();
  
              TableRow newRow = new TableRow();
              TableCell newcell = new TableCell();
  
              int adder = 0;
              while (adder &lt;= solCount)
              {
                  solutions.Rows.Add(newRow);
                  for (int i = 0; i &lt;= 6; i++)
                  {
                      newRow.Cells.Add(newcell);
                      newcell.Text = subject[adder].ToString();
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>Obviously I'm a bit green with it all. Basically what happens is it pulls all of the solution titles from a database and I want the titles to each be in a cell of their own, where I will go on to link them to the respective pages. Hopefully it all makes sense, if not I am happy to provide more information.</p>