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. C#
  4. Convert string to Enumeration

Convert string to Enumeration

Scheduled Pinned Locked Moved C#
help
5 Posts 3 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.
  • B Offline
    B Offline
    babutkchn
    wrote on last edited by
    #1

    Hi All, Greetings. I've to assign the enum value to a object property. Which shows the following error. Cannot convert type 'string' to 'Common.Enumerations.OffDate' searchUIO.OffDate = (OffDate)ddlOffDate.SelectedValue; in this (OffDate) is an enum. the drop down list will contain the values lastweek, lastmonth like that. so i have to assing the value to the lefthand site object. thanks in advance Regards babu

    S M 2 Replies Last reply
    0
    • B babutkchn

      Hi All, Greetings. I've to assign the enum value to a object property. Which shows the following error. Cannot convert type 'string' to 'Common.Enumerations.OffDate' searchUIO.OffDate = (OffDate)ddlOffDate.SelectedValue; in this (OffDate) is an enum. the drop down list will contain the values lastweek, lastmonth like that. so i have to assing the value to the lefthand site object. thanks in advance Regards babu

      S Offline
      S Offline
      Stefan Troschuetz
      wrote on last edited by
      #2

      Take a look at the static Enum.Parse method.


      "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

      www.troschuetz.de

      1 Reply Last reply
      0
      • B babutkchn

        Hi All, Greetings. I've to assign the enum value to a object property. Which shows the following error. Cannot convert type 'string' to 'Common.Enumerations.OffDate' searchUIO.OffDate = (OffDate)ddlOffDate.SelectedValue; in this (OffDate) is an enum. the drop down list will contain the values lastweek, lastmonth like that. so i have to assing the value to the lefthand site object. thanks in advance Regards babu

        M Offline
        M Offline
        Martin 0
        wrote on last edited by
        #3

        Hello, As enum is an int type, you could make the enum casting with the SelectedIndex method. searchUIO.OffDate = (OffDate)ddlOffDate.SelectedIndex; All the best, Martin

        B 1 Reply Last reply
        0
        • M Martin 0

          Hello, As enum is an int type, you could make the enum casting with the SelectedIndex method. searchUIO.OffDate = (OffDate)ddlOffDate.SelectedIndex; All the best, Martin

          B Offline
          B Offline
          babutkchn
          wrote on last edited by
          #4

          Thank you for your response. But i need to take the text value from the dropdown list.how i can do that??? Could you tell me the solution. regards babu

          M 1 Reply Last reply
          0
          • B babutkchn

            Thank you for your response. But i need to take the text value from the dropdown list.how i can do that??? Could you tell me the solution. regards babu

            M Offline
            M Offline
            Martin 0
            wrote on last edited by
            #5

            Have you tried the solution "Stefan Troschütz" posted?

            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