62,075
社区成员
发帖
与我相关
我的任务
分享
<form id="form1" runat="server">
<div>
<asp:Table ID="Table1" runat="server"</asp:Table>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
</div>
</form>
TableRow tr;
TableCell td;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
tr = new TableRow();
td = new TableCell();
td.Text = "新增的行1";
tr.Cells.Add(td);
Table1.Controls.Add(tr);
}
public class MyTextBox : System.Web.UI.Page
{
public static List<TextBox> myTextBoxList;
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
MyTextBox.myTextBoxList = new List<TextBox>();
}
else
{
for (int i = 0; i < MyTextBox.myTextBoxList.Count; i++)
{
TableRow tr = new TableRow();
TableCell td = new TableCell();
td.Controls.Add(MyTextBox.myTextBoxList[i]);
tr.Cells.Add(td);
Table1.Controls.Add(tr);
}
}
}
protected void Button1_Click1(object sender, EventArgs e)
{
TableRow tr = new TableRow();
TableCell td = new TableCell();
TextBox tb = new TextBox();
tb.ID = "tb" + MyTextBox.myTextBoxList.Count;
td.Controls.Add(tb);
tr.Cells.Add(td);
Table1.Controls.Add(tr);
MyTextBox.myTextBoxList.Add(tb);
}
<html>
<head>
<script>
function Add()
{
var tbody1 = document.getElementById("tbody1");
var tr = document.createElement("<tr>");
var td = document.createElement("<td>");
var text = document.createTextNode("新增的行");
td.appendChild(text);
tr.appendChild(td);
tbody1.appendChild(tr);
}
</script>
</head>
<body>
<table id="table1" border=1>
<tbody id="tbody1">
</table>
<input type="button" onclick="Add()" value="Add">
</body>
</html>