|
string name = "dfdfs"; HtmlTable tab_mid1 = new HtmlTable(); HtmlTableRow tr = new HtmlTableRow(); HtmlTableCell tc = new HtmlTableCell(); tc.Width="34%"; tc.InnerHtml="<a href=\"#\"><strong><font color=\"#336633\">"+name+"</font></strong></a>"; tr.Cells.Add(tc); tab_mid1.Rows.Add(tr); Page.Controls.Add(tab_mid1); 例二. <script runat="server" language="C#"> void Page_Load() { //create a new HTMLTable object HtmlTable table1 = new HtmlTable(); HtmlTableRow row; HtmlTableCell cell; //set the table's styles table1.Border =1; table1.CellPadding =3; table1.CellSpacing =3; table1.BorderColor ="red"; for(int i=1; i<=5; i++) { //create a new row and set its background color row = new HtmlTableRow(); row.BgColor =(i%2==0 ?"lightyellow" : "lightcyan"); for(int j=1; j<=4; j++) { //create a cell and set its text cell = new HtmlTableCell(); cell.InnerHtml ="Row :" + i.ToString()+ "<br>Cell:"+j.ToString(); //add the cell to the current row row.Cells.Add(cell); } //add the row to the table table1.Rows.Add(row); } //add the table to page Page.Controls.Add(table1); } </script>
|