C#后台创建表格和后台获取前台的表格

今天遇到了一个棘手的问题,需要前台获取一个表格中的tr的ID问题,开始还疑惑,

其实想明白就好 就是加上runat=“server” 就可以,在后台就可以获取到了

如下

可以把前台table或则tr 添加 runat="server" id="mytr".然后后台直接使用mytr.visible或mytr.Attributes,Add("style","display:none");

后台创建表格就更简单了

呵呵

Table table = new Table();
        table.BorderColor = System.Drawing.Color.Black;
        table.BorderWidth = 1;
        TableRow row1 = new TableRow();
        TableCell cell1 = new TableCell();
        cell1.Text = "fddfdss";
        row1.Cells.Add(cell1);
        TableCell cell2 = new TableCell();
        cell2.Controls.Add(Label1);
        row1.Cells.Add(cell2);
        table.Rows.Add(row1);
        form1.Controls.Add(table);
        aaa.Visible = false;

希望对大家有用!!!!

posted @ 2011-07-06 17:27  真名一世  阅读(3086)  评论(3编辑  收藏  举报