表控件(Table)

ASP.NET Table控件动态创建示例

 表控件(Table).aspx

 

 <asp:Table ID="Table1" runat="server" CellPadding ="10" GridLines ="both" HorizontalAlign ="center" >
            
<asp:TableRow >
                
<asp:TableCell Text ="(0,0)"></asp:TableCell>
                
<asp:TableCell Text ="(0,1)"></asp:TableCell>
                
<asp:TableCell Text ="(0,2)"></asp:TableCell>
            
</asp:TableRow>
            
<asp:TableRow >
                
<asp:TableCell Text ="(1,0)"></asp:TableCell>
                
<asp:TableCell Text ="(1,1)"></asp:TableCell>
                
<asp:TableCell Text ="(1,2)"></asp:TableCell>
            
</asp:TableRow>
        
</asp:Table>

cs

 

protected void Page_Load(object sender, EventArgs e)
    
...{
        TableItemStyle tableStyle 
= new TableItemStyle();
        tableStyle.HorizontalAlign 
= HorizontalAlign.Center;
        tableStyle.VerticalAlign 
= VerticalAlign.Middle;
        tableStyle.Width 
= Unit.Pixel(100);
        
for (int i = 2; i < 10; i++)
        
...{
            TableRow tempRow 
= new TableRow();
            
for (int j = 0; j < 3; j++)
            
...{
                TableCell tempCell 
= new TableCell();
                tempCell.Text 
= "(" + i + "," + j + ")";
                tempRow.Cells.Add(tempCell);
            }

            Table1.Rows.Add(tempRow);
        }

        
foreach (TableRow r in Table1.Rows)
               
foreach (TableCell c in r.Cells )
                c.ApplyStyle(tableStyle);
        TableHeaderCell header 
= new TableHeaderCell();
        header.RowSpan 
= 1;
        header.ColumnSpan 
= 3;
        header.Text 
= "测试表格显示";
        header.BackColor 
=Color.Red;
        header.Font.Bold 
= true;
        header.HorizontalAlign 
= HorizontalAlign.Center;
        header.VerticalAlign 
= VerticalAlign.Middle;

        TableRow headerRow 
= new TableRow();
        headerRow.Cells.Add(header);

        Table1.Rows.AddAt(
0, headerRow);
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值