繁体   English   中英

vb.net中列表框可见性的代码

[英]code for visibility of listbox in vb.net

  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

我在上面的代码中遇到问题。 我希望在dropdownlist的值更改时使列表框可见。 有人知道吗?

每当您选择其他项目时,下拉菜单的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。 Uou可以发布一些标记和代码以使其清楚。

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM