我正在编写一个 ASP.NET 页面,它从数据库中读取数据并需要在表格中显示它。出于某种原因,我不想使用 gridView。
如何在 HTML 页面的表格中显示数据?
这是我的 C# 代码:
SqlConnection thisConnection = new SqlConnection(dbConnection);
SqlCommand thisCommand = thisConnection.CreateCommand();
thisCommand.CommandText = "SELECT * from Test";
thisConnection.Open();
SqlDataReader reader = thisCommand.ExecuteReader();
while (reader.Read())
{
int id = reader.GetInt32(0);
string Name = reader.GetString(1);
string Pass = reader.GetString(2);
}
thisConnection.Close();
这是我的 ASPX 页面:
<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/test.master" CodeFile="test.aspx.cs" Inherits="test" %>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="ContentPlaceHolder">
<table width="100%" align="center" cellpadding="2" cellspacing="2" border="0" bgcolor="#EAEAEA" >
<tr align="left" style="background-color:#004080;color:White;" >
<td> ID </td>
<td> Name </td>
<td>Pass</td>
</tr>
**<%--Need the while output into here--%>**
</table>
</asp:Content>