简体   繁体   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

I am facing problem in above code. 我在上面的代码中遇到问题。 I want to make listbox visible when the value of dropdownlist get changed. 我希望在dropdownlist的值更改时使列表框可见。 Does any one know that? 有人知道吗?

Dropdown's SelectedIndexChange will fire every time you select a different item. 每当您选择其他项目时,下拉菜单的SelectedIndexChange都会触发。 But you are making the ListBox visible only when SelectedIndex =1. 但是,只有在SelectedIndex = 1时才使ListBox可见。 Remove the SelectedIndex condition like this: 删除SelectedIndex条件,如下所示:

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

And ListBox will be visible each time DropDown selection changes. 每次DropDown选择更改时,ListBox都将可见。

BTW: It is not clear how you are setting visibility of the listbox to false. 顺便说一句:尚不清楚如何将列表框的可见性设置为false。 Uou can post some markup and code to make it clear. Uou可以发布一些标记和代码以使其清楚。

You can use the following code to get the listbox to appear on ANY change in the value of the dropdownlist 您可以使用以下代码来使列表框显示在下拉列表的值的任何更改上

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

However if you want to change when the user selects the first/second or nth item, you can use this 但是,如果要在用户选择第一/第二或第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