62,074
社区成员
发帖
与我相关
我的任务
分享
<%@ Page Language="C#" AutoEventWireup="True" %>
<html>
<head>
<script language="C#" runat="server">
void Page_Load(Object sender, EventArgs e) {
// Generate rows and cells.
int numrows = 3;
int numcells = 2;
for (int j=0; j<numrows; j++) {
TableRow r = new TableRow();
for (int i=0; i<numcells; i++) {
TableCell c = new TableCell();
c.Controls.Add(new LiteralControl("row " + j.ToString() + ", cell " + i.ToString()));
r.Cells.Add(c);
}
Table1.Rows.Add(r);
}
}
</script>
</head>
<body>
<h3>Table Example, constructed programmatically</h3>
<form runat=server>
<asp:Table id="Table1"
GridLines="Both"
HorizontalAlign="Center"
Font-Name="Verdana"
Font-Size="8pt"
CellPadding=15
CellSpacing=0
Runat="server"/>
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default15.aspx.cs" Inherits="Default15" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function AddRow(currentRow)
{
debugger
var panel = document.getElementById('test');
var tr = panel.insertRow(currentRow.rowIndex+1);
tr.id = "row"+Math.random;
tr.onclick = function(){AddRow(tr);};
var cells = currentRow.cells.length;
for(i = 0;i<cells;i++)
{
var td = tr.insertCell();
td.innerHTML ='cell'+i;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<table border="1" id="test">
<tr onclick="AddRow(this)" id="ro1">
<td >
1
</td>
<td >
==
</td>
</tr>
<tr id="row2" onclick="AddRow(this)">
<td >
2
</td>
<td >
==
</td>
</tr>
<tr id="ro3" onclick="AddRow(this)">
<td >
3
</td>
<td >
==
</td>
</tr>
</table>
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default15.aspx.cs" Inherits="Default15" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function AddRow(currentRow)
{
var panel = document.getElementById('test');
var tr = panel.insertRow(currentRow.rowIndex+1);
var td = tr.insertCell();
td.innerHTML ='d';
}
</script>
</head>
<body>
<form id="form1" runat="server">
<table border="1" id="test">
<tr onclick="AddRow(this)" id="ro1">
<td >
Row1
</td>
</tr>
<tr id="row2" onclick="AddRow(this)">
<td >
Row2
</td>
</tr>
<tr id="ro3" onclick="AddRow(this)">
<td >
Row3
</td>
</tr>
</table>
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default15.aspx.cs" Inherits="Default15" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function AddRow(currentRow)
{
var panel = document.getElementById('test');
var tr = panel.insertRow(currentRow.rowIndex+1);
var td = tr.insertCell();
td.innerHTML ='d';
}
</script>
</head>
<body>
<form id="form1" runat="server">
<table border="1" id="test">
<tr onclick="AddRow(this)" id="ro1">
<td >
Row1
</td>
</tr>
<tr id="row2" onclick="AddRow(this)">
<td >
Row2
</td>
</tr>
<tr id="ro3" onclick="AddRow(this)">
<td >
Row3
</td>
</tr>
</table>
</form>
</body>
</html>