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. set the selected value for drop down from a database query (VB.NET)

set the selected value for drop down from a database query (VB.NET)

Scheduled Pinned Locked Moved Visual Basic
databasequestioncsharphelp
4 Posts 4 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.
  • K Offline
    K Offline
    kjalandoon
    wrote on last edited by
    #1

    I manually set my drop down items (ex. MyDropDown.Items.Add("something")) since our database is not yet complete data and to avoid typographical errors. Basically i just want to know how can i set the selected value of my DropDownList based from my database query. to explain further my problem ill give a scenario: my dropdown items defined as "a", "b", "c". then the result of my query is "c" ... how can i set "c" as my 'SelectedValue'? thanks in advance! :)

    V C L 3 Replies Last reply
    0
    • K kjalandoon

      I manually set my drop down items (ex. MyDropDown.Items.Add("something")) since our database is not yet complete data and to avoid typographical errors. Basically i just want to know how can i set the selected value of my DropDownList based from my database query. to explain further my problem ill give a scenario: my dropdown items defined as "a", "b", "c". then the result of my query is "c" ... how can i set "c" as my 'SelectedValue'? thanks in advance! :)

      V Offline
      V Offline
      Vimalsoft Pty Ltd
      wrote on last edited by
      #2

      hi Look at this Article , but instead use a Combobox http://www.codeproject.com/KB/vb/N-Tier_Application_VB.aspx[^] its Simple

      Vuyiswa Maseko, Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding VB.NET/SQL7/2000/2005 http://vuyiswamb.007ihost.com http://Ecadre.007ihost.com vuyiswam@tshwane.gov.za

      1 Reply Last reply
      0
      • K kjalandoon

        I manually set my drop down items (ex. MyDropDown.Items.Add("something")) since our database is not yet complete data and to avoid typographical errors. Basically i just want to know how can i set the selected value of my DropDownList based from my database query. to explain further my problem ill give a scenario: my dropdown items defined as "a", "b", "c". then the result of my query is "c" ... how can i set "c" as my 'SelectedValue'? thanks in advance! :)

        C Offline
        C Offline
        chandralekha
        wrote on last edited by
        #3

        You can select the needed value from the database.If DropDownList1 be the dropdownlist which contain the values a,b,c,d.You can make the selected item of the dropdownlist as that value.If you used a DataReader to retrive the data from database DropDownList1.SelectedItem =dr(0).ToString() where dr is my DataReader Hope This Code Help You

        1 Reply Last reply
        0
        • K kjalandoon

          I manually set my drop down items (ex. MyDropDown.Items.Add("something")) since our database is not yet complete data and to avoid typographical errors. Basically i just want to know how can i set the selected value of my DropDownList based from my database query. to explain further my problem ill give a scenario: my dropdown items defined as "a", "b", "c". then the result of my query is "c" ... how can i set "c" as my 'SelectedValue'? thanks in advance! :)

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          If the DropDown's style is set to something other than DropDownList then you can just do DropDown.SelectedText = "c". (Setting DropDown.SelectedText when the DropDownStyle is set to DropDownList won't have any effect.) Or, perhaps you might want to save the SelectedIndex instead of the Text? That way you can just set the SelectedIndex when you retrieve the value from the database.

          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