0
  Protected Sub DropDownList2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList2.SelectedIndexChanged
        MsgBox("OK")
        If (DropDownList2.SelectedIndex) = 1 Then
            ListBox1.Visible = True
        End If
    End Sub

我在上面的代码中遇到问题。当下拉列表的值发生更改时,我想让列表框可见。有人知道吗?

4

2 回答 2

1

每次您选择不同的项目时,下拉的 SelectedIndexChange 都会触发。但是只有在 SelectedIndex =1 时才使 ListBox 可见。像这样删除 SelectedIndex 条件:

Protected Sub DropDownList2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList2.SelectedIndexChanged
        'MsgBox("OK")
        ListBox1.Visible = True
End Sub

每次 DropDown 选择更改时,ListBox 都将可见。

顺便说一句: 目前尚不清楚您如何将列表框的可见性设置为 false。您可以发布一些标记和代码以使其清楚。

于 2013-09-13T08:48:07.780 回答
0

您可以使用以下代码使列表框出现在下拉列表值的任何更改上

Protected Sub DropDownList2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList2.SelectedIndexChanged

Dim cs As ClientScriptManager = Page.ClientScript

 cs.RegisterClientScriptBlock(Me.GetType(), "MyScript", "<script type=""text/javascript""> Alert("Ok"); </script>", False);
 ListBox1.Visible = True
    End Sub

但是,如果您想在用户选择第一个/第二个或第 n 个项目时进行更改,您可以使用此

 Protected Sub DropDownList2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList2.SelectedIndexChanged

    Dim cs As ClientScriptManager = Page.ClientScript

     cs.RegisterClientScriptBlock(Me.GetType(), "MyScript", "<script type=""text/javascript""> Alert("Ok"); </script>", False);


if DropDownList2.SelectedIndex = 0  //makes the listbox visible only when you select the first item, Use 1 for making the list box visible on the selection of the second item, so on and so forth.
     ListBox1.Visible = True
end if

        End Sub
于 2013-09-13T09:25:26.950 回答