How to get the value of dropdown list
-
hi, this is kinda simple in vb6 but in vb.net its a different story. I'm trying to get the value of the select item in my dropdown list box and try to display the selected item in a label or textbox but I can't find a way to do it. Can anyone help me with this problem? Here is the sample code I've made to do the thing. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim DbOraConnection As New DBConnection drpHOList.DataSource = DbOraConnection.stnOraConnect drpHOList.DataValueField = ("PURCEN_NAME") drpHOList.DataBind() End Sub Protected Sub drpHOList_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles drpHOList.SelectedIndexChanged 'lblname.Text = drpHOList.SelectedValue If Not Page.IsPostBack Then lblname.Text = drpHOList.SelectedItem.Value End If End Sub Hope that you can help me. Thank you in advance. :)
-
hi, this is kinda simple in vb6 but in vb.net its a different story. I'm trying to get the value of the select item in my dropdown list box and try to display the selected item in a label or textbox but I can't find a way to do it. Can anyone help me with this problem? Here is the sample code I've made to do the thing. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim DbOraConnection As New DBConnection drpHOList.DataSource = DbOraConnection.stnOraConnect drpHOList.DataValueField = ("PURCEN_NAME") drpHOList.DataBind() End Sub Protected Sub drpHOList_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles drpHOList.SelectedIndexChanged 'lblname.Text = drpHOList.SelectedValue If Not Page.IsPostBack Then lblname.Text = drpHOList.SelectedItem.Value End If End Sub Hope that you can help me. Thank you in advance. :)
For drop down list (combobox) you can use drpHOList.text
-
For drop down list (combobox) you can use drpHOList.text
-
Hi, the code you gave works. but, only when the form 1st load and when you try to choose another item from the list box. The text in the label wont change its text to value of the item that I choose in the list box.
HI... I think you had put that code in form load only... You have to put the same code in
SelectedIndexChanged
event of Dropdownlist also.
In dpListCombo_SelectedIndexChanged
LBlSelectName.text = dpListCombo.text