显示从SQL Server中的表到ASP.Net中的HTML表的数据 [英] Displaying data from a table in sql server to a HTML table in ASP.Net
本文介绍了显示从SQL Server中的表到ASP.Net中的HTML表的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将sql server表中的数据检索到Asp.Net中的HTML表.任何人都可以为我提供源代码.
I want to retrieve the data in a table in sql server to a HTML table in Asp.Net.Can anyone provide me the source code for that.
推荐答案
您可以获取数据集中的数据,然后使用div并为其分配runat = server属性.然后,您可以使用字符串生成器来创建HTML表,如下所示.
You can get the data in a dataset and then use a div and assign runat = server property to it. Then you can use string builder to create the HTML table as shown below.
StringBuilder strResults = new StringBuilder();
strResults.Append("<table>");
for (int i = 0; i <= ds.tables(0).rows.Count; i++) {
strResults.Append("<tr>");
strResults.Append("<td>");
strResults.Append(ds.tables(0).rows(i)("ColumnName"));
strResults.Append("</td>");
strResults.Append("<tr>");
}
strResults.Append("</table>");
divResults.innerHTML = strResults.ToString();
在此处找到它 [
found it here[^]
以下是示例:
Here is an example:
Dim da As New SqlDataAdapter(Query, conn)
Dim table As New DataTable()
da.Fill(table)
Dim filename As String = "temp.html"
Dim sbrHTML As System.Text.StringBuilder
sbrHTML = New System.Text.StringBuilder()
sbrHTML.Append("<TABLE Border=1px cellspacing=0 cellpadding=0>")
sbrHTML.Append("<tr align='Center'><td colspan='16'>Report of " & DropDownList11.SelectedItem.ToString() & " For 2011-2012</td></tr>")
这篇关于显示从SQL Server中的表到ASP.Net中的HTML表的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文