如何做一个比较HTML表格使用ASP中继器(数据旋转) [英] How to make a comparison html table using asp repeater (data rotation)
问题描述
我需要在HTML格式的比较表中,问题是,项
在数据库来作为列,但在比较表它必须是一个行<!/ P>
示例
在数据库中的数据如下所示
ID名称颜色重量
-------------------------------
1红球10
2表黑色50
3椅子绿30
,它必须看起来像比较表
以下 ID 1 2 3
名称波尔表椅子
颜色红黑绿
重量10 50 30
我使用与中继ASP.NET,但它没有工作,
能否请你帮我找做到这一点的最好办法。
因为比较表列数不同,我必须使用类似中继器。
一个可能的解决方案:
由于以下数据表作为数据源:
保护数据的DataTable
{
得到
{
如果(的ViewState [数据] == NULL)
{
数据表表=新的DataTable();
table.Columns.Add(ID的typeof(INT));
table.Columns.Add(姓名);
table.Columns.Add(颜色);
table.Columns.Add(重量的typeof(INT)); table.Rows.Add(1,球,红,10);
table.Rows.Add(2,表,黑,50);
table.Rows.Add(3,主席,绿色,30);
的ViewState [数据] =表;
}
返回(数据表)的ViewState [数据];
}
}
和一些ASP code为循环和建表:
&LT;表&gt;
&LT;%
的for(int i = 0; I&LT; Data.Columns.Count;我++)
{
%GT;
&所述; TR&GT;
&LT; TD&GT;&LT;%= Data.Columns [I] .ColumnName%GT;&LT; / TD&GT;
&LT;%
对于(INT J = 0; J&LT; Data.Rows.Count; J ++)
{
%GT;
&LT; TD&GT;&LT;%= Data.Rows [J] [I]%GT;&LT; / TD&GT;
&LT;%
} %GT;
&LT; / TR&GT;
&LT;%
}
%GT;
&LT; /表&gt;
I need to make a comparison table in HTML format, the problem is that the items in database comes as a columns but in comparison table it must be a rows!
Example
The data in database looks like the following
ID Name Color Weight
-------------------------------
1 Ball Red 10
2 Table Black 50
3 Chair Green 30
And it must looks like the following in comparison table
ID 1 2 3
Name Ball Table Chair
Color Red Black Green
Weight 10 50 30
I am using ASP.NET with repeater but it didn't work, Can you please help me to find the best way to do this.
I must use something like repeater because the numbers of columns in the the comparison table varies.
A possible solution:
Given the following DataTable as datasource:
protected DataTable Data
{
get
{
if (ViewState["Data"] == null)
{
DataTable table = new DataTable();
table.Columns.Add("ID", typeof(int));
table.Columns.Add("Name");
table.Columns.Add("Color");
table.Columns.Add("Weight", typeof(int));
table.Rows.Add(1, "Ball", "Red", 10);
table.Rows.Add(2, "Table", "Black", 50);
table.Rows.Add(3, "Chair", "Green", 30);
ViewState["Data"] = table;
}
return (DataTable)ViewState["Data"];
}
}
And some ASP code for looping and building the table:
<table>
<%
for (int i = 0; i < Data.Columns.Count; i++)
{
%>
<tr>
<td><%= Data.Columns[i].ColumnName %></td>
<%
for (int j = 0; j < Data.Rows.Count; j++)
{
%>
<td><%= Data.Rows[j][i] %></td>
<%
}
%>
</tr>
<%
}
%>
</table>
这篇关于如何做一个比较HTML表格使用ASP中继器(数据旋转)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!