📄 htmltable.aspx
字号:
<html>
<head>
<script language="C#" runat="server">
void Page_Load(Object sender, EventArgs e) {
string[] myArray = { "red", "green", "yellow" , "white"};//单元格背景色矩阵
int numrows = int.Parse(Select1.Value); //读取表格行数
int numcells = int.Parse(Select2.Value);//读取表格的列数
for (int j=0; j<numrows; j++) {
HtmlTableRow myRow = new HtmlTableRow();//创建新的HtmlTableRow类的对象
for (int i=0; i<numcells; i++) {
HtmlTableCell myCell = new HtmlTableCell();//创建新的HtmlTableCell类的对象
myCell.BgColor=myArray[(i+j)%4];//为单元格设置背景色
//在单元格中显示单元格坐标
myCell.Controls.Add(new LiteralControl("(" + j.ToString() + "," + i.ToString()+")"));
//将单元格对象添加到表格行对象中
myRow.Cells.Add(myCell);
}
//将表格行对象添加到表格对象中
Table1.Rows.Add(myRow);
}
}
</script>
</head>
<body>
<form runat=server>
<table id="Table1" CellPadding=5 CellSpacing=0 Border="1" runat="server" />
<p>
表格行数:
<select id="Select1" runat="server">
<option Value="1">1</option>
<option Value="2">2</option>
<option Value="3">3</option>
<option Value="4">4</option>
</select>
<br>
表格列数:
<select id="Select2" runat="server">
<option Value="1">1</option>
<option Value="2">2</option>
<option Value="3">3</option>
<option Value="4">4</option>
</select>
<input type="submit" value="生成表格" runat="server">
</form>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -