簡體   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