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. displaying results on dropdownlist

displaying results on dropdownlist

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

    Hi I am displaying locations on dropdownlist so the problem is if i have selected record which is not in the database it gives me this error" 'ddlLocation' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value " here is my code and is working perfect if the record is in the database If strPerNo = "" Then Session("samacc") = HttpContext.Current.User.Identity.Name.ToLower emp = cEmp.GetEmp(Session("samacc")) 'empPhoto = cEmp.DisplayPhoto(emp.perno) Else emp = cEmp.GetEmpByPerNo(strPerNo) 'btnAdmin.Text = "UPDATE" End If If emp.perno = "" Then Response.Write(Session("samacc") + " not found") Else Session("perno") = emp.perno Response.Write(emp.name + " " + emp.surname) Session("ImgPerNr") = emp.perno txtFirstname.Text = emp.name txtLastname.Text = emp.surname txtDivision.Text = emp.BsUnit lblBU.Text = emp.BsUnit txtBlock.Text = emp.block txtFloor.Text = emp.floorno txtRoom.Text = emp.roomno txtInt.Text = emp.Int1 txtTel.Text = emp.tel txtAltTelNo.Text = emp.alttel txtCell.Text = emp.cellno txtAltCell.Text = emp.altcellno txtEmail.Text = emp.email txtFax.Text = emp.fax txtAltEmail.Text = emp.altemail If ddlLocation.SelectedValue <> "0" Then ddlLocation.SelectedValue = emp.LocID Else ddlLocation.SelectedValue = 0 End If

    Mamphekgo

    B 1 Reply Last reply
    0
    • M Mamphekgo Bahula

      Hi I am displaying locations on dropdownlist so the problem is if i have selected record which is not in the database it gives me this error" 'ddlLocation' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value " here is my code and is working perfect if the record is in the database If strPerNo = "" Then Session("samacc") = HttpContext.Current.User.Identity.Name.ToLower emp = cEmp.GetEmp(Session("samacc")) 'empPhoto = cEmp.DisplayPhoto(emp.perno) Else emp = cEmp.GetEmpByPerNo(strPerNo) 'btnAdmin.Text = "UPDATE" End If If emp.perno = "" Then Response.Write(Session("samacc") + " not found") Else Session("perno") = emp.perno Response.Write(emp.name + " " + emp.surname) Session("ImgPerNr") = emp.perno txtFirstname.Text = emp.name txtLastname.Text = emp.surname txtDivision.Text = emp.BsUnit lblBU.Text = emp.BsUnit txtBlock.Text = emp.block txtFloor.Text = emp.floorno txtRoom.Text = emp.roomno txtInt.Text = emp.Int1 txtTel.Text = emp.tel txtAltTelNo.Text = emp.alttel txtCell.Text = emp.cellno txtAltCell.Text = emp.altcellno txtEmail.Text = emp.email txtFax.Text = emp.fax txtAltEmail.Text = emp.altemail If ddlLocation.SelectedValue <> "0" Then ddlLocation.SelectedValue = emp.LocID Else ddlLocation.SelectedValue = 0 End If

      Mamphekgo

      B Offline
      B Offline
      Bassam Saoud
      wrote on last edited by
      #2

      mamphekgojakes wrote:

      ddlLocation.SelectedValue = emp.LocID

      Does the value of emp.LocID exist in the Drop down. You get such an error when you set the selectedvallue to a value that doesnt exist in the Drop down item collection

      M 1 Reply Last reply
      0
      • B Bassam Saoud

        mamphekgojakes wrote:

        ddlLocation.SelectedValue = emp.LocID

        Does the value of emp.LocID exist in the Drop down. You get such an error when you set the selectedvallue to a value that doesnt exist in the Drop down item collection

        M Offline
        M Offline
        Mamphekgo Bahula
        wrote on last edited by
        #3

        if the value does exist how can assign 0 to non existing values

        Mamphekgo

        B 1 Reply Last reply
        0
        • M Mamphekgo Bahula

          if the value does exist how can assign 0 to non existing values

          Mamphekgo

          B Offline
          B Offline
          Bassam Saoud
          wrote on last edited by
          #4

          you add like a "Select One" Item to the drop down list with a value of 0, and then you set the selected value to 0 if the item dont exist. So you have to loop the dropdown to check if the value you are setting exist or not.

          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