在组合框VB​​.Net中选择文本时更改标签

时间:2013-12-21 07:03:32

标签: vb.net

我有一个包含两个选项的组合框。从下拉列表中选择一个选项时,我希望标签的文本在其上方相应地更改。有没有一种简单的方法可以用事件做到这一点?

我感谢任何回复。

3 个答案:

答案 0 :(得分:2)

试试这个

您需要在combobox selectedIndex change event

中编写此代码

例如:

Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DropDownList1.SelectedIndexChanged
        Label1.Text= DropDownList1.SelectedItem.Text.ToString()
End Sub

并且您需要在PageLoad事件

中设置DropDownList.AutoPostBack=true

答案 1 :(得分:1)

根据您的控件进行更改..

Private Sub YourComboBox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles YourComboBox.Click

    UrLabel.Text = YourComboBox.SelectedValue

End Sub

答案 2 :(得分:0)

<强> Asp.net

<强>组合框

您需要设置 AutoPostBAck =“true”

<table>
            <tr>
                <td><asp:ComboBox ID="cmb" runat="server" AutoPostBack="True">
            <asp:ListItem>1</asp:ListItem>
            <asp:ListItem>2</asp:ListItem>
            </asp:ComboBox></td>

        <td>
            <asp:Label ID="lbl" runat="server"></asp:Label>
        </td>
            </tr>
        </table>

.aspx文件(代码隐藏)

Protected Sub cmb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmb.SelectedIndexChanged
        lbl.Text = cmb.SelectedValue
    End Sub

<强> Asp.net

<强>的DropDownList

您需要设置 AutoPostBAck =“true”

<table>
            <tr>
                <td><asp:DropDownList ID="ddl" runat="server" AutoPostBack="True">
            <asp:ListItem>1</asp:ListItem>
            <asp:ListItem>2</asp:ListItem>
            </asp:DropDownList></td>

        <td>
            <asp:Label ID="lbl" runat="server"></asp:Label>
        </td>
            </tr>
        </table>

.aspx文件(代码隐藏)

Protected Sub ddl_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ddl.SelectedIndexChanged
        lbl.Text = ddl.SelectedValue
    End Sub