我在寫一個ASP.NET頁面,它從數據庫讀取數據並需要在表格中顯示它。出於某種原因,我不想使用gridView。在ASP.NET的html表中顯示數據
如何在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>
ü可以請給予完整的解決方案??或者任何的例子嗎?或示例鏈接??我無法得到你。謝謝。但我需要將輸出加載到page_loader中 – riad
它在使用html頁面中的<%#getWhileLoopData()%>時顯示錯誤。 – riad
只是使用<%Response.Write(getWhileLoopData())%>或<%= getWhileLoopData()%>。 – Mortalus