导航

asp.net表格控件Table(实例动态增加表格)

Posted on 2010-08-04 11:32  ykhi  阅读(11276)  评论(0)    收藏  举报

Table服务器控件的主要用途是以编程方式处理表格中的信息,这些信息可以是文字,也可以是其他WEB服务器控件的实例。

在下面的实例中我们实现单击添加按钮时添加表格的一行数据,其中第一列放入了一个label,第二列是文本信息。

页面代码:

<asp:Table ID="Table1" BorderWidth="1" runat="server">
</asp:Table>
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="添加表格" />

aspx.cs代码:

protected void Button1_Click(object sender, EventArgs e)
{
TableRow row
= new TableRow();
Label label1
= new Label();
label1.Text
= "表格第一列";
TableCell cell1
= new TableCell();
cell1.Font.Size
= FontUnit.Large;
cell1.Controls.Add(label1);
row.Cells.Add(cell1);
TableCell cell2
= new TableCell();
cell2.Font.Size
= FontUnit.Large;
cell2.ForeColor
= System.Drawing.Color.Blue;
cell2.Text
= "表格第二列";
row.Cells.Add(cell2);
Table1.Rows.Add(row);
}

运行效果:点击添加按钮后

尊重知识,尊重版权,转载请注明:心蕊网页设计http://xin126.cn/ 原创