在页面上的HTML服务器控牛的声明和普通的静态HTML标签的声明一样,使用附加的runat="server"特性,充高尔夫Asp.net处理服务器类,并把它们翻译成对应的.net类的实例。
//在Page_Load事件中添加如下代码
protected void Page_Load(object sender, EventArgs e)
{
HtmlTable Table = new HtmlTable();
Table.CellPadding = 5;
Table.CellSpacing = 5;
Table.Border = 1;
HtmlTableRow row;
HtmlTableCell cell;
for (int i = 1; i <= 10; i++)
{
row = new HtmlTableRow();
row.BgColor = i % 2 == 0 ? "lightyellow" : "lightcyan";
for (int j = 1; j <= 5; j++)
{
cell = new HtmlTableCell();
cell.InnerText = string.Format("{0}行{1}列", i, j);
row.Cells.Add(cell);
}
Table.Rows.Add(row);
}
this.Controls.Add(Table);
}
protected void Page_Load(object sender, EventArgs e)
{
HtmlTable Table = new HtmlTable();
Table.CellPadding = 5;
Table.CellSpacing = 5;
Table.Border = 1;
HtmlTableRow row;
HtmlTableCell cell;
for (int i = 1; i <= 10; i++)
{
row = new HtmlTableRow();
row.BgColor = i % 2 == 0 ? "lightyellow" : "lightcyan";
for (int j = 1; j <= 5; j++)
{
cell = new HtmlTableCell();
cell.InnerText = string.Format("{0}行{1}列", i, j);
row.Cells.Add(cell);
}
Table.Rows.Add(row);
}
this.Controls.Add(Table);
}