How to get a selected value of a dropdown list


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: How to get a selected value of a dropdown list

  1. #1
    shawn Guest

    How to get a selected value of a dropdown list


    I was wondering if anyone could tell me how to get the value of the item selected
    from a listbox or a Dropdownlistbox. This is very is to do in vb6 but I am
    having lots of problems in the vb.net. I appreciate the help.

    If at all possible I'd like to stick with the vb coding and away from HTML
    Please reply to

    sroozrokh@18004insure.com
    Thanks

  2. #2
    David Rothgery Guest

    Re: How to get a selected value of a dropdown list

    Since I'm not exactly sure which listbox or dropdownlist you're talking
    about...

    For WebControls, use the SelectedItem.Value property

    For HtmlControls, use the Value property (though you might have to something
    different with a multi-select enabled list box).

    For windows forms, use the SelectedValue property


    "shawn" <sroozrokh@3704@18004insure.com> wrote in message
    news:3d4efd66$1@10.1.10.29...
    >
    > I was wondering if anyone could tell me how to get the value of the item

    selected
    > from a listbox or a Dropdownlistbox. This is very is to do in vb6 but I am
    > having lots of problems in the vb.net. I appreciate the help.
    >
    > If at all possible I'd like to stick with the vb coding and away from HTML
    > Please reply to
    >
    > sroozrokh@18004insure.com
    > Thanks




  3. #3
    the localhost with the most Guest

    Re: How to get a selected value of a dropdown list

    "shawn" <sroozrokh@3704@18004insure.com> wrote in message
    news:3d4efd66$1@10.1.10.29...
    >
    > I was wondering if anyone could tell me how to get the value of the item

    selected
    > from a listbox or a Dropdownlistbox. This is very is to do in vb6 but I am
    > having lots of problems in the vb.net. I appreciate the help.
    >
    > If at all possible I'd like to stick with the vb coding and away from HTML


    Hi there.
    Make up a new standard windows project, and add a listbox and a command
    button to the form.
    Then add this code:

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load
    ListBox1.Items.Add("Sausage")
    ListBox1.Items.Add("Burger")
    ListBox1.Items.Add("Pie")
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles Button1.Click
    MessageBox.Show(ListBox1.SelectedItem.ToString)
    End Sub

    run your app, select a list item, and press the button.

    Hopefully this will get you started.



  4. #4
    Rodney Hall Guest

    Re: How to get a selected value of a dropdown list


    "the localhost with the most" <local@host.com> wrote:
    >"shawn" <sroozrokh@3704@18004insure.com> wrote in message
    >news:3d4efd66$1@10.1.10.29...
    >>
    >> I was wondering if anyone could tell me how to get the value of the item

    >selected
    >> from a listbox or a Dropdownlistbox. This is very is to do in vb6 but

    I am
    >> having lots of problems in the vb.net. I appreciate the help.
    >>
    >> If at all possible I'd like to stick with the vb coding and away from

    HTML
    >
    >Hi there.
    >Make up a new standard windows project, and add a listbox and a command
    >button to the form.
    >Then add this code:
    >
    >Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
    >System.EventArgs) Handles MyBase.Load
    > ListBox1.Items.Add("Sausage")
    > ListBox1.Items.Add("Burger")
    > ListBox1.Items.Add("Pie")
    >End Sub
    >
    >Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
    >System.EventArgs) Handles Button1.Click
    > MessageBox.Show(ListBox1.SelectedItem.ToString)
    >End Sub
    >
    >run your app, select a list item, and press the button.
    >
    >Hopefully this will get you started.
    >
    >

    Hi,

    Just to clarify, there are two things available from the selected item.
    You can get the text or the value of the selected item. In the dropdown
    list you can assign a value such as an index number to each list item, and
    there is the text value as well.

    To access the text: dropdownlist.SelectedItem.ToString
    To access the value: dropdownlist.SelectedItem.Value

    Rodney


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center