很抱歉,如果这个问题看起来很奇怪或者很明显的话,但是我是c#的新手。
我正在visual中用C#制作一个web应用程序,并且我有一个html table。我想用sql server的一张桌子填充它。
以下是我的HTML表:
<%@ 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>当我单击button时,我希望用我在这里创建的datatable填充该表:
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;
}
}
}UATConnectionString正在工作(我几乎是阳性的),所以现在我只需要从连接到HTMLtable的SQLtable中获取数据。
如果有人能帮我,我会很感激的。如果还需要更多的信息,我很乐意提供帮助。
发布于 2014-08-19 16:13:33
为此,您应该使用Repeater控件。您可以在这里看到一个很好的例子:http://msdn.microsoft.com/en-us/library/zzx23804(v=vs.85).aspx
https://stackoverflow.com/questions/25388046
复制相似问题