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. Web Development
  3. ASP.NET
  4. datasource on asp:dropdownlist is null after a postback

datasource on asp:dropdownlist is null after a postback

Scheduled Pinned Locked Moved ASP.NET
designhelpquestion
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.
  • A Offline
    A Offline
    AlexG2119
    wrote on last edited by
    #1

    I have a dropdownlist who's datasource is a ObjectCollection. I have 3 variables within the Object. The Dropdown list works fine and shows the name variable from the object. Below is some code that explains what i'm doing however I get a compiler error that the cast can't be done. int number = ((Object)dropdownlist1.selecteditem).num; For some reason i get a cannot convert a type system.web.ui.listitem to projectname.int Any ideas?

    K 1 Reply Last reply
    0
    • A AlexG2119

      I have a dropdownlist who's datasource is a ObjectCollection. I have 3 variables within the Object. The Dropdown list works fine and shows the name variable from the object. Below is some code that explains what i'm doing however I get a compiler error that the cast can't be done. int number = ((Object)dropdownlist1.selecteditem).num; For some reason i get a cannot convert a type system.web.ui.listitem to projectname.int Any ideas?

      K Offline
      K Offline
      Kannan Ar
      wrote on last edited by
      #2

      It is because you converted the selecteditem to an object which doesn't have the num property. What is projectname.int? projectname is a class? Can you please show the code that you use to bind the dropdownlist?

      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