<table id="table1" >
<% var list=this.GetData();
for (int i=0;i<list.Count();i++)
{ %>
<tr>
<td>
<% list[i].ToString(); %> //list items are not shown on webpage
</td>
</tr>
<%}
%>
</table>
`
试试这个
只需使用<%: list[i] %>
而不是<% list[i].ToString(); %>
<table id="table1">
<% var list = this.GetData();
for (int i = 0; i < list.Count(); i++)
{ %>
<tr>
<td>
<%: list[i] %>
//list items are not shown on webpage
</td>
</tr>
<%}
%>
</table>
要了解有关 Asp.net 内联标签的更多信息,请访问此处。
但是,您应该考虑Microsoft为此目的提供的Repeater
和其他data binding controls
。
看看 asp.net 数据控件。
在asp.net 中,有更好的方法将数据绑定到页面。