【问题标题】:Increment Table with button带按钮的增量表
【发布时间】:2012-12-02 23:27:21
【问题描述】:

我有表格和按钮,我想通过单击按钮来增加该表格,我该如何实现?

我的表是这样的

<table> <tr> <td colspan="2"> Information </td></tr> <tr> <td> city </td> <td> <asp:TextBox ID="tCity" runat="server"> </asp:TextBox> </td></tr> <tr> <td> state </td> <td> <asp:TextBox ID="tState" runat="server"> </asp:TextBox> </td></tr> <tr> <td> zip </td> <td> <asp:TextBox ID="tZip" runat="server"> </asp:TextBox> </td></tr></table> <asp:LinkButton ID="AddNew" runat="server" />

例子

                 Information
          City       ---------
          State      ---------
          Zip        ---------
                  Add New Button

点击我想要的按钮后

                Information
          City       ---------
          State      ---------
          Zip        ---------
                Information
          City       ----------
          State      ---------
          Zip        ---------
                 Add New Button

我尝试使用 Gridview 但我不知道逻辑,我也在谷歌上搜索但没有找到任何东西。 +

【问题讨论】:

    标签: c# asp.net auto-increment


    【解决方案1】:

    您想做的事情在理论上听起来很容易,但在实践中却不是那么容易。 您必须在按钮单击事件中动态创建控件,将它们添加到页面中,然后在 OnInit 中重新创建它们以获取绑定到它们的视图状态。

    您应该阅读 ASP.NET 中的动态控件:http://aspnet.4guysfromrolla.com/articles/092904-1.aspx

    祝你好运!

    【讨论】:

      【解决方案2】:

      让这有点棘手的是您混合了客户端控件(即table)和服务器端控件(asp:textbox)。如果您要创建该表runat="server",则可以向您的按钮添加一个点击处理程序,并在代码隐藏中以编程方式添加新的TableRows 和TableCells 以​​及您想要的任何内容。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-08-02
        • 1970-01-01
        相关资源
        最近更新 更多