Sorry in advance if this question seems strange or obvious but I am a very new to c#.
I'm making a web application with C#
in visual studio, and I have an html table
. I'd like to populate it with a table from sql server
.
Here is my HTML Table:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="MRAApplication.test" %>
<!DOCTYPE html>
<body>
<form runat="server">
<asp:Button ID="populateButton" runat="server" Text="Table" onClick="populateButton_Click" />
</form>
<table id="table1">
<thead>
<tr>
<th>AlertID</th>
<th>AccountID</th>
<th>Alert</th>
<th>Active</th>
<th>IsShow</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</body>
And when I click the button
I'd like the table to be filled with a datatable that I'm creating here:
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;
}
}
}
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.
If anybody could help me I would appreciate it. If there is any more information needed I will be glad to help.