在组合框中选择文本时更改标签VB.Net
问题描述:
我有一个包含两个选项的组合框。从下拉列表中选择一个选项时,我希望标签的文字在其上方进行相应更改。有没有一种简单的方法可以做到这一点事件呢?在组合框中选择文本时更改标签VB.Net
我很感激任何答复。
答
试试这个
你需要写在组合框中的selectedIndex更改事件的代码
如:
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
事件
答
变化取决于您的控件..
Private Sub YourComboBox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles YourComboBox.Click
UrLabel.Text = YourComboBox.SelectedValue
End Sub
答
Asp.net
组合框
您需要设置的AutoPostBack = “真”
<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 = “真”
<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
combobox.SelectedItem.Text错误,但是combobox.SelectedItem没有。仍然帮我弄明白了,谢谢 – user3105998
我已经更新了解决方案。请检查这个 –
我使用它作为If语句,并且发现这对我来说工作正常:如果combobox.SelectedItem =“Text” – user3105998