【问题标题】:Create dropdownlist and two textbox each time when click button每次单击按钮时创建下拉列表和两个文本框
【发布时间】:2018-02-13 13:49:00
【问题描述】:

我正在尝试每次单击按钮以添加一个下拉列表(使用 EF 从数据库中填充)和两个动态文本框, 然后将列表和文本框中的值存储到数据库中。

如何使用 asp.nrt(vb) 和 EF 做到这一点?

【问题讨论】:

  • SO 不是为代码编写服务而设计的。问你在实施过程中遇到的问题,而不是要求社区做你的功课。
  • 是的,你说得对,谢谢你的建议

标签: asp.net vb.net entity-framework


【解决方案1】:

首先,您需要在客户端设置一个面板来保存您的新文本框,以及如下下拉列表:

<asp:Panel ID="pnlButton" runat="server" Width="100%"/>

然后你会想要为你的按钮点击设置一个这样的事件。

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim tb As New TextBox
        tb.ID = "TextBox1"
        Dim ddl As New DropDownList
        ddl.ID = "DropDownList1"
        ddl.DataSource = 'your data source from the Database'
        pnlButton.Controls.Add(tb)
        pnlButton.Controls.Add(ddl)
    End Sub

这应该让您至少开始动态创建控件。

【讨论】:

    猜你喜欢
    • 2013-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-26
    • 1970-01-01
    • 1970-01-01
    • 2022-08-19
    • 1970-01-01
    相关资源
    最近更新 更多