1 看你的方法应该在做MVC Demo 测试的吧!
1
|
public
ActionResult Index(){}
|
//这个应该是可以显示出来,因为你单独取到的是String字符串
1
|
<h2><%: ViewData[
"Message"
] %></h2>
|
你这样写肯定是错误的,
1
2
3
|
<asp:Table id=
"Table1"
runat =
"server"
>
//这样写显示不出来
</asp:Table>
<%:ViewData[
"tb"
] %>
//这样写也显示不出来
|
ViewData["tb"]这个存是张表对象Table,不可能跟你展现出HTML标签啊.拼接方式;
如果要显示出来:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
<table border=
"0"
cellspacing=
"0"
cellpadding=
"0"
width=
"100%"
>
<%
Table tb=(Table)ViewData[
"tb"
];
foreach
(TableRow tr
in
tb.Rows )
{
%>
<tr>
<%
foreach
(TableCell td
in
tr.Cells)
{
%>
<td><%=td.Text %></td>
<%
}
%>
</tr>
<%
}
%>
</table>
|
我测试了一下,可能显示出来表三行四列信息.你拿去运行一下吧.
在前台拖一个asp.net的Table 取名 tabShow
<asp:Table ID="tabShow" runat="server" CssClass="table_th_left" >
</asp:Table>
后台自己写一个方法,比如BindTable
Private Void BindTable()
{
this.tabShow.Rows.Clear(); //将数据清空
// 有个带数据的list
for (int i = 0; i < list.Count; i++)
{
TableRow row = new TableRow();//行
TableCell cell = new TableCell(); //第一列
cell.Text = "我是第一列";
row.Cells.Add(cell); //将列添加到行
TableCell cell2 = new TableCell();
cell.Text = "我是第二列";
row.Cells.Add(cell2); //将列添加到行
TableCell cell9 = new TableCell();
Button bt = new Button(); //此列加个删除按钮
bt.Text = "删除";
bt.ID = list[i].id.ToString();
bt.CssClass = "btn";
bt.Click +=new EventHandler(bt_Click); //为按钮添加单击事件
cell9.Controls.Add(bt); //将按钮添加到列
row.Cells.Add(cell9);
...
this.tabShow.Rows.Add(row); //最后将行添加到拖的tabShow中
}
}