title: Add Headers to Table control and retrieving data from database
body: <p>I use Table control from ToolBox and retrieve data from database. My code is working but when I try to add a header to the table, I can not get the header correctly at its place.</p>
  
  <p>My Code:</p>
  
  <pre><code>    DataTable tbl = new DataTable()`;
      conn.Open();
      cmd.Connection = conn;
      cmd.CommandText = "select ........   ";
      SqlDataAdapter adp = new SqlDataAdapter(cmd);
      DataSet ds = new DataSet();
      adp.Fill(tbl);
      // Current row count.
      int rowCtr;
      // Total number of cells per row (columns).
      int cellCtr;
      // Current cell counter
      int cellCnt;
      cellCnt = 2;
  
  for (rowCtr = 1; rowCtr &lt;= num; rowCtr++)
  {
      // Create new row and add it to the table.
  
      TextBox tbx = new TextBox();
      Label lbl = new Label();
  
      for (cellCtr = 1; cellCtr &lt;= cellCnt; cellCtr++)
      {
          TableCell tCell = new TableCell();
  
          if (cellCtr == 1)
          {
              lbl.ID = "lblData" + cellCtr;
              lbl.Text = ds.Tables["MyTableName"].Rows[rowCtr - 1][cellCtr - 1].ToString();
              tCell.Text = lbl.Text;
          }
          else if (cellCtr == 2)
          {
              tbx.ID = "txtData" + cellCtr;
              tbx.Enabled = true;
              tbx.Text = ds.Tables["MyTableName"].Rows[rowCtr - 1][cellCtr - 1].ToString();
              tCell.Text = tbx.Text;
          }
          tRow.Cells.Add(tCell);
      }
  }
  conn.Close();
  </code></pre>