62,074
社区成员
发帖
与我相关
我的任务
分享
<table style="width: 100%" border="1" runat="server" id="mx">
<tr>
<td align="left" style="width: 100px;">
姓名:
</td>
<td align="left">
<asp:TextBox ID="TextBox23" CssClass="underline" Width="100px" runat="server"></asp:TextBox>
</td>
<td align="left" colspan="2">
身份证号:
<asp:TextBox ID="TextBox24" runat="server"
CssClass="underline" Width="100px"></asp:TextBox>
<asp:Button ID="Button2" runat="server" Font-Size="12px" Text="添加一行" OnClick="AddNew" />
</td>
</tr>
</table>
protected void AddNew(object sender, EventArgs e)
{
HtmlTableRow row = new HtmlTableRow();
HtmlTableCell cell;
TextBox tb;
cell = new HtmlTableCell();
cell.InnerText = "姓名:";
row.Cells.Add(cell);
cell = new HtmlTableCell();
tb = new TextBox();
tb.ID = "tb" + mx.Rows.Count.ToString();
tb.CssClass = "underline";
tb.Width = Unit.Pixel(100);
tb.Font.Size = FontUnit.Point(9);
cell.Controls.Add(tb);
row.Cells.Add(cell);
cell = new HtmlTableCell();
tb = new TextBox();
tb.ID = "tb_" + mx.Rows.Count.ToString();
tb.CssClass = "underline";
tb.Width = Unit.Pixel(100);
tb.Font.Size = FontUnit.Point(9);
cell.Controls.Add(tb);
cell = new HtmlTableCell();
cell.InnerText = "身份证号:";
tb = new TextBox();
tb.ID = "tb__" + mx.Rows.Count.ToString();
tb.CssClass = "underline";
tb.Width = Unit.Pixel(100);
tb.Font.Size = FontUnit.Point(9);
cell.Controls.Add(tb);
row.Cells.Add(cell);
mx.Rows.Add(row);
}
protected void Page_Load(object sender, EventArgs e)
{
if (ViewState["Count"] != null)
{
for (int i = 0; i < Convert.ToInt16(ViewState["Count"]); i++)
{
AddRow();
}
}
if (!IsPostBack)
{
ViewState["Count"] = 0;
}
}
public void AddRow(){
HtmlTableRow row = new HtmlTableRow();
HtmlTableCell cell;
TextBox tb;
cell = new HtmlTableCell();
cell.InnerText = "姓名:";
row.Cells.Add(cell);
cell = new HtmlTableCell();
tb = new TextBox();
tb.ID = "tb" + mx.Rows.Count.ToString();
tb.CssClass = "underline";
tb.Width = Unit.Pixel(100);
tb.Font.Size = FontUnit.Point(9);
cell.Controls.Add(tb);
row.Cells.Add(cell);
cell = new HtmlTableCell();
tb = new TextBox();
tb.ID = "tb_" + mx.Rows.Count.ToString();
tb.CssClass = "underline";
tb.Width = Unit.Pixel(100);
tb.Font.Size = FontUnit.Point(9);
cell.Controls.Add(tb);
cell = new HtmlTableCell();
cell.InnerText = "身份证号:";
tb = new TextBox();
tb.ID = "tb__" + mx.Rows.Count.ToString();
tb.CssClass = "underline";
tb.Width = Unit.Pixel(100);
tb.Font.Size = FontUnit.Point(9);
cell.Controls.Add(tb);
row.Cells.Add(cell);
mx.Rows.Add(row);
}
protected void AddNew(object sender, EventArgs e)
{
AddRow();
ViewState["Count"] = Convert.ToInt16(ViewState["Count"]) + 1;
}