您的位置:首页 > Web前端 > HTML

使用HtmlControl动态创建一个表格

2012-07-06 15:46 344 查看
usingSystem;


usingSystem.Collections.Generic;


usingSystem.Linq;


usingSystem.Web;


usingSystem.Web.UI;


usingSystem.Web.UI.WebControls;


usingSystem.Web.UI.HtmlControls;




publicpartialclassChapter04_CreateTableByCode:System.Web.UI.Page


{


//使用Html服务器控件创建一个5行4列的表格


protectedvoidPage_Load(objectsender,EventArgse)


{


HtmlTabletable=newHtmlTable();


table.Border=1;


table.CellSpacing=3;


table.CellPadding=3;


table.BorderColor="red";




HtmlTableRowrow;


HtmlTableCellcell;


for(inti=1;i<=5;i++)


{


row=newHtmlTableRow();


row.BgColor=i%2==0?"lightyellow":"lightcyan";


for(intj=1;j<=4;j++)


{


cell=newHtmlTableCell();


cell.InnerHtml="Row:"+i.ToString()+"<br/>Cell:"+j.ToString();


row.Cells.Add(cell);


}


table.Rows.Add(row);


}


this.Controls.Add(table);


}


}


效果:



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: