ASP动态添加表单行

时间:2017-05-01 14:57:19

标签: c# asp.net

我有一个用户输入的基本表单。我正在尝试添加一个控件,以允许用户根据需要添加更多行。当AddRow_Click执行

时,我无法更新UI
<form id="Form1" runat="server">
    <asp:Table ID="InputTable" runat="server" Width="100%">
            <asp:TableHeaderRow>
            <asp:TableHeaderCell>Description</asp:TableHeaderCell>
            <asp:TableHeaderCell>Location</asp:TableHeaderCell>
            <asp:TableHeaderCell>Name of Person Responsible</asp:TableHeaderCell>
            </asp:TableHeaderRow>   

            <asp:TableCell><asp:TextBox ID="Desc" placeholder="Description" runat="server" Width="100%"></asp:TextBox></asp:TableCell>
            <asp:TableCell><asp:TextBox ID="Loc" placeholder="Location" runat="server" Width="100%"></asp:TextBox></asp:TableCell>
            <asp:TableCell><asp:TextBox ID="Nm" placeholder="Name of Person Responsible" runat="server" Width="100%"></asp:TextBox></asp:TableCell>
    </asp:Table>

    <asp:Button id="AddRow" Text="Add Row" OnClick="AddRow_Click" runat="server" />
    <asp:Button id="DltRow" Text="Delete Row" OnClick="DltRow_Click" runat="server" />
</form>

C#代码

   protected void AddRow_Click(object sender, EventArgs e)
{
    TableRow row = new TableRow();
    TableCell cell1 = new TableCell();
    cell1.Text = @"< asp:TextBox ID = 'Tag' placeholder = 'Dynamic Tag' runat = 'server' Width = '100%' ></ asp:TextBox >";
    InputTable.Rows.Add(row);

}

修改 我试过这个但仍然不正确

    TableRow row = new TableRow();
    TableCell cell1 = new TableCell();
    TextBox txtbx = new TextBox();
    cell1.Controls.Add(txtbx);
    this.InputTable.Rows.Add(row);

0 个答案:

没有答案