title: Populate HTML Table with a DataTable
body: <p>Sorry in advance if this question seems strange or obvious but I am a very new to c#.</p>
  
  <p>I'm making a web application with <code>C#</code> in visual studio, and I have an html <code>table</code>.  I'd like to populate it with a table from <code>sql server</code>.</p>
  
  <p>Here is my HTML Table:</p>
  
  <pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test.aspx.cs"  Inherits="MRAApplication.test" %&gt;
  &lt;!DOCTYPE html&gt;
  &lt;body&gt;
  &lt;form runat="server"&gt;
  &lt;asp:Button ID="populateButton" runat="server" Text="Table" onClick="populateButton_Click" /&gt;
  &lt;/form&gt;
   &lt;table id="table1"&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;AlertID&lt;/th&gt;
              &lt;th&gt;AccountID&lt;/th&gt;
              &lt;th&gt;Alert&lt;/th&gt;
              &lt;th&gt;Active&lt;/th&gt;
              &lt;th&gt;IsShow&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
      &lt;/tbody&gt;
  &lt;/table&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>And when I click the <code>button</code> I'd like the table to be filled with a datatable that I'm creating here:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Data;
  using System.Data.SqlClient;
  using System.Linq;
  using System.Web;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  using System.Configuration;
  
  namespace MRAApplication
  {
  public partial class test : System.Web.UI.Page
  {
      protected void populateButton_Click(object sender, EventArgs e)
      {
          GetDataTable();
      }
      public static System.Data.DataTable GetDataTable()
      {
          string queryString = "Select * FROM Alerts";
          string conn =     ConfigurationManager.ConnectionStrings["UATConnectionString"].ToString();
          SqlDataAdapter adapter = new SqlDataAdapter(queryString, conn);
          System.Data.DataTable dt = new System.Data.DataTable();
          dt.TableName = "Table";
          using (System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter(queryString, conn))
          {
              da.Fill(dt);
          }
          return dt;
      }
  }
  }
  </code></pre>
  
  <p>The UATConnectionString is working (I'm almost positive), so now I just need to get the data from the SQLtable I'm connecting to into the HTMLtable.</p>
  
  <p>If anybody could help me I would appreciate it.  If there is any more information needed I will be glad to help.</p>