在组合框中选择文本时更改标签 VB.Net
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20716503/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change Label When Selecting Text In A Combo Box VB.Net
提问by user3105998
I have a combo box with two selections. When selecting a option from the drop down, I want a label's text to change accordingly above it. Is there an easy way to do this with an event maybe?
我有一个有两个选择的组合框。从下拉列表中选择一个选项时,我希望标签的文本在其上方进行相应更改。有没有一种简单的方法可以通过事件来做到这一点?
I appreciate any replies.
我感谢任何答复。
回答by Vignesh Kumar A
Try this
尝试这个
You need to write this code in combobox selectedIndex change event
您需要在组合框 selectedIndex 更改事件中编写此代码
eg:
例如:
Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DropDownList1.SelectedIndexChanged
Label1.Text= DropDownList1.SelectedItem.Text.ToString()
End Sub
and You need to set DropDownList.AutoPostBack=truein PageLoad Event
并且您需要DropDownList.AutoPostBack=true在 PageLoad 事件中设置
回答by AdorableVB
change depending on your controls..
根据您的控件更改..
Private Sub YourComboBox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles YourComboBox.Click
UrLabel.Text = YourComboBox.SelectedValue
End Sub
回答by Amarnath Balasubramanian
Asp.net
Asp.net
ComboBox
组合框
You need to set AutoPostBAck = "true"
您需要设置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 file (Code behind)
.aspx 文件(隐藏代码)
Protected Sub cmb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmb.SelectedIndexChanged
lbl.Text = cmb.SelectedValue
End Sub
Asp.net
Asp.net
DropDownList
下拉列表
You need to set AutoPostBAck = "true"
您需要设置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 file (Code behind)
.aspx 文件(隐藏代码)
Protected Sub ddl_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ddl.SelectedIndexChanged
lbl.Text = ddl.SelectedValue
End Sub

