文件1: Deafaultaspx
<%@ Page Language="C#" CodeFile="Defaultaspxcs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 10 Transitional//EN" "http://wwww3org/TR/xhtml1/DTD/xhtml1-transitionaldtd">
<html xmlns="http://wwww3org/1999/xhtml" >
<head runat="server">
<title>HtmlTable演示</title>
</head>
<body>
<h1>HtmlTable实例演示</h1>
<form id="Form1" runat="server">
<table id="MyTable" cellpadding="5" cellspacing="0" border="1" runat="server" >
<tbody>
</tbody>
</table><p>
输入表格行数:
<input type="text" id="MyTextOne" value="1" runat="server"/></p>
<p>输入表格单元格:
<input type="text" id="MyTextTwo" value="1" runat="server" /></p>
<p><input id="Submit1" type="submit" value="产生表格" runat="server" onserverclick="Submit1_ServerClick" /></p>
</form>
</body>
</html>
文件2:Deafaultaspxcs
using System;
using SystemData;
using SystemConfiguration;
using SystemWeb;
using SystemWebSecurity;
using SystemWebUI;
using SystemWebUIWebControls;
using SystemWebUIWebControlsWebParts;
using SystemWebUIHtmlControls;
public partial class _Default : SystemWebUIPage
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Submit1_ServerClick(object sender, EventArgs e)
{
int row = 0;
int numrows = ConvertToInt32(MyTextOneValue); // 获得文本框中整型数
int numcells = ConvertToInt32(MyTextTwoValue);
for (int j = 0; j < numrows; j++)
{
HtmlTableRow r = new HtmlTableRow();
if (row % 2 == 1)// 设置行的背景色
rBgColor = "Gainsboro";
row++;
for (int i = 0; i < numcells; i++)
{
HtmlTableCell c = new HtmlTableCell(); //创建单元格对象
cControlsAdd(new LiteralControl("行: " + (j + 1)ToString() + ", 单元格: " +(i + 1)ToString()));
rCellsAdd(c); //添加该单元格对象
}
MyTableRowsAdd(r);//添加行对
}
HtmlTableRow r2 = new HtmlTableRow();
HtmlTableCell c2 = new HtmlTableCell();
c2ControlsAdd(new LiteralControl("吉林大学远程教育学院"));
c2ColSpan = 3; //合并单元格,colspan属性可以实现单元格跨越多列
r2CellsAdd(c2);
MyTableRowsAdd(r2);
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)