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. Selecting a value from downdownlist

Selecting a value from downdownlist

Scheduled Pinned Locked Moved Visual Basic
databasehelp
2 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
    Mamphekgo Bahula
    wrote on last edited by
    #1

    Hi i have managed to populate dropdownlist from database so i want to select a value from dropdownlist and insert it into database.The problem is when ever i select a value it always select the first value regardless of what i choose.everything is working except dropdownlist here is my code cmdEmployee.Parameters.Add("@Emp_No", SqlDbType.Int).Value = TextBox1.Text cmdEmployee.Parameters.Add("@Location_ID", SqlDbType.Int).Value = DropDownList1.SelectedItem.Value cmdEmployee.Parameters.Add("@Tel", SqlDbType.VarChar).Value = txtTel.Text.ToString() cmdEmployee.Parameters.Add("@Fax", SqlDbType.VarChar).Value = txtFax.Text.ToString() cmdEmployee.Parameters.Add("@Cell", SqlDbType.VarChar).Value = txtCell.Text.ToString() cmdEmployee.Parameters.Add("@Alternative", SqlDbType.VarChar).Value = txtAlternative.ToString() cmdEmployee.Parameters.Add("@Block", SqlDbType.VarChar).Value = txtBlock.Text.ToString() cmdEmployee.Parameters.Add("@Floor1", SqlDbType.VarChar).Value = txtFloor.Text.ToString() cmdEmployee.Parameters.Add("@Room_Number", SqlDbType.VarChar).Value = txtRoom.Text.ToString() cmdEmployee.ExecuteNonQuery()

    Mamphekgo

    G 1 Reply Last reply
    0
    • M Mamphekgo Bahula

      Hi i have managed to populate dropdownlist from database so i want to select a value from dropdownlist and insert it into database.The problem is when ever i select a value it always select the first value regardless of what i choose.everything is working except dropdownlist here is my code cmdEmployee.Parameters.Add("@Emp_No", SqlDbType.Int).Value = TextBox1.Text cmdEmployee.Parameters.Add("@Location_ID", SqlDbType.Int).Value = DropDownList1.SelectedItem.Value cmdEmployee.Parameters.Add("@Tel", SqlDbType.VarChar).Value = txtTel.Text.ToString() cmdEmployee.Parameters.Add("@Fax", SqlDbType.VarChar).Value = txtFax.Text.ToString() cmdEmployee.Parameters.Add("@Cell", SqlDbType.VarChar).Value = txtCell.Text.ToString() cmdEmployee.Parameters.Add("@Alternative", SqlDbType.VarChar).Value = txtAlternative.ToString() cmdEmployee.Parameters.Add("@Block", SqlDbType.VarChar).Value = txtBlock.Text.ToString() cmdEmployee.Parameters.Add("@Floor1", SqlDbType.VarChar).Value = txtFloor.Text.ToString() cmdEmployee.Parameters.Add("@Room_Number", SqlDbType.VarChar).Value = txtRoom.Text.ToString() cmdEmployee.ExecuteNonQuery()

      Mamphekgo

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      It sounds like you are rebinding the dropdown list on postback. That would remove everything in it that came from the postback, including the selection, and the first item gets selected by default. Use the IsPostback property to determine if the page is loading for the first time or not, and only bind the dropdownlist on the first load.

      Despite everything, the person most likely to be fooling you next is yourself.

      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