asp.net 自己拼table

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中


  }


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值