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. Enum Problem

Enum Problem

Scheduled Pinned Locked Moved ASP.NET
questioncsharpasp-netdatabasehelp
6 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.
  • S Offline
    S Offline
    Sachin Dubey
    wrote on last edited by
    #1

    I defined a enum as public enum Access { Guest = 1, Public = 2, Center = 4, Member = 8, Trader = 16 } there are 5 checkboxes in my asp.net page suppose user checked Guest and Center then Value of center and Guest i.e.(1+4=5) 5 will save in Database in integar field.. Now my Question is I am getting Value from database like categoriesDTO.CatAccess = (Access)r["CategoryStatus"]; Now enum has value 5... So how can i check these 2 checkboxes of center and Guest Thanx In advance

    C N 2 Replies Last reply
    0
    • S Sachin Dubey

      I defined a enum as public enum Access { Guest = 1, Public = 2, Center = 4, Member = 8, Trader = 16 } there are 5 checkboxes in my asp.net page suppose user checked Guest and Center then Value of center and Guest i.e.(1+4=5) 5 will save in Database in integar field.. Now my Question is I am getting Value from database like categoriesDTO.CatAccess = (Access)r["CategoryStatus"]; Now enum has value 5... So how can i check these 2 checkboxes of center and Guest Thanx In advance

      C Offline
      C Offline
      Coding C
      wrote on last edited by
      #2

      You cannot! How you think you will make 5 into 4 and 1??? It could either be 2 and 3!! Save comma separated values like 1,4 in database and then fetch, split and use them. HTH

      Coding C# ExciteTemplate

      N 1 Reply Last reply
      0
      • C Coding C

        You cannot! How you think you will make 5 into 4 and 1??? It could either be 2 and 3!! Save comma separated values like 1,4 in database and then fetch, split and use them. HTH

        Coding C# ExciteTemplate

        N Offline
        N Offline
        Not Active
        wrote on last edited by
        #3

        Coding C# wrote:

        How you think you will make 5 into 4 and 1???

        Ever heard of bit flags?


        only two letters away from being an asset

        S 1 Reply Last reply
        0
        • S Sachin Dubey

          I defined a enum as public enum Access { Guest = 1, Public = 2, Center = 4, Member = 8, Trader = 16 } there are 5 checkboxes in my asp.net page suppose user checked Guest and Center then Value of center and Guest i.e.(1+4=5) 5 will save in Database in integar field.. Now my Question is I am getting Value from database like categoriesDTO.CatAccess = (Access)r["CategoryStatus"]; Now enum has value 5... So how can i check these 2 checkboxes of center and Guest Thanx In advance

          N Offline
          N Offline
          Not Active
          wrote on last edited by
          #4

          Add the Flags attribute to your enumeration and you can use it like this[^] or a simple example here[^]


          only two letters away from being an asset

          1 Reply Last reply
          0
          • N Not Active

            Coding C# wrote:

            How you think you will make 5 into 4 and 1???

            Ever heard of bit flags?


            only two letters away from being an asset

            S Offline
            S Offline
            Sachin Dubey
            wrote on last edited by
            #5

            Hi all.. My question is Genuine.. Bcoz if stored value is 5 it means only 1 and 4 checkbox has to be checked. No other Chekbox make combination of 2 +3 bcoz 2 is a value but 3 is not there

            N 1 Reply Last reply
            0
            • S Sachin Dubey

              Hi all.. My question is Genuine.. Bcoz if stored value is 5 it means only 1 and 4 checkbox has to be checked. No other Chekbox make combination of 2 +3 bcoz 2 is a value but 3 is not there

              N Offline
              N Offline
              Not Active
              wrote on last edited by
              #6

              Sachin Dubey wrote:

              My question is Genuine..

              and so is my answer below


              only two letters away from being an asset

              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