Reputation: 45
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.
Upvotes: 0
Views: 9505
Reputation: 9460
Asp.net
ComboBox
You need to set 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)
Protected Sub cmb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmb.SelectedIndexChanged
lbl.Text = cmb.SelectedValue
End Sub
Asp.net
DropDownList
You need to set 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)
Protected Sub ddl_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ddl.SelectedIndexChanged
lbl.Text = ddl.SelectedValue
End Sub
Upvotes: 0
Reputation: 28403
Try this
You need to write this code in combobox selectedIndex change event
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=true
in PageLoad Event
Upvotes: 2
Reputation: 1393
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
Upvotes: 1