在VB中的每个Click事件上添加一个链接按钮

时间:2014-09-12 13:16:40

标签: vb.net onclick

我有一个下拉列表,其中包含一堆产品名称,旁边有一个添加按钮。每次按下添加按钮,我都希望链接按钮显示产品名称。我做了pnl.Controls.Add(New LinkBut​​ton),但它只添加一个然后在我下次点击时消失。以下是我现在的代码,即在点击时显示LinkBut​​ton,只是无法弄清楚每次添加新逻辑的逻辑。

Private Sub btnAddLinkedProjects_Click(sender As Object, e As EventArgs) Handles btnAddLinkedProjects.Click


    lbLinkedProject.Visible = True

    lbLinkedProject.Text = ddlParentProject.SelectedItem.Text


End Sub

我的设计师中有一个链接按钮,在它被点击之前设置为隐形。最终,当点击项目的链接按钮时,它会填充所有这样的字段

Private Sub lbLinkedProject_Click(sender As Object, e As EventArgs) Handles lbLinkedProject.Click

    Dim intParentRecID As Integer
    Dim pid As Project = Nothing
    Dim intCityState As Integer = 0
    Dim strState As String = ""
    Dim cs As nsCityState = Nothing

    intParentRecID = Integer.Parse(ddlParentProject.SelectedValue)

    pid = oDesignCon.getProjectByRecID(intParentRecID)
    If pid Is Nothing Then
    Else
        intCityState = pid.CityState
        cs = New nsCityState(intCityState)
        If cs Is Nothing Then
        Else
            strState = cs.StateShort
            Me.ddlAddState.SelectedValue = strState
            Call HandleAddStateChanged()
        End If

        Call nsLinqFormBinder.LoadContainer(Me.pnlCreateNewPID, pid)
        Me.ddlAddAssignTo.SelectedIndex = 0

    End If

End Sub

1 个答案:

答案 0 :(得分:0)

如果您像往常一样创建新的LinkButton会出现什么问题:

Private Sub btnAddLinkedProjects_Click(sender As Object, e As EventArgs) Handles btnAddLinkedProjects.Click
    'create & prepare new LinkButton'
    Dim newLinkedProject As New LinkButton
    newLinkedProject.Visible = True
    newLinkedProject.Text = ddlParentProject.SelectedItem.Text
    'register event handler'
    AddHandler newLinkedProject.Click, AddressOf Me.lbLinkedProject_Click
    'add the LinkButton to panel'
    pnl.Controls.Add(newLinkedProject)
End Sub