Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. How to get the value of dropdown list

How to get the value of dropdown list

Scheduled Pinned Locked Moved Visual Basic
helpcsharptutorialquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    meki_2118
    wrote on last edited by
    #1

    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. :)

    N 1 Reply Last reply
    0
    • M meki_2118

      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. :)

      N Offline
      N Offline
      nishkarsh_k
      wrote on last edited by
      #2

      For drop down list (combobox) you can use drpHOList.text

      M 1 Reply Last reply
      0
      • N nishkarsh_k

        For drop down list (combobox) you can use drpHOList.text

        M Offline
        M Offline
        meki_2118
        wrote on last edited by
        #3

        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.

        N 1 Reply Last reply
        0
        • M meki_2118

          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.

          N Offline
          N Offline
          nishkarsh_k
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups