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. Color.Translator.FromHtml inside off @Html.DisplayFor Issue -Razor

Color.Translator.FromHtml inside off @Html.DisplayFor Issue -Razor

Scheduled Pinned Locked Moved ASP.NET
helphtmlasp-netdatabasegraphics
9 Posts 4 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
    Alem B
    wrote on last edited by
    #1

    I have some data from model , in which i getting some hex values .. now i need to translate this hex values to real color. I have try this way... @Html.DisplayFor(modelItem=>System.Drawing.ColorTranslator.FromHtml(item.color)) But this not working. item.Color is a value from database and it's like this #ffffff; Any suggestions ? Thanks for help in advance!

    A P Richard DeemingR 3 Replies Last reply
    0
    • A Alem B

      I have some data from model , in which i getting some hex values .. now i need to translate this hex values to real color. I have try this way... @Html.DisplayFor(modelItem=>System.Drawing.ColorTranslator.FromHtml(item.color)) But this not working. item.Color is a value from database and it's like this #ffffff; Any suggestions ? Thanks for help in advance!

      A Offline
      A Offline
      Ali Al Omairi Abu AlHassan
      wrote on last edited by
      #2

      try this

      <span style="display: inline-block; width: 20px; height: 20px; background-color: @item.Color"></span>

      it would display like this:

      Help people,so poeple can help you.

      A 1 Reply Last reply
      0
      • A Alem B

        I have some data from model , in which i getting some hex values .. now i need to translate this hex values to real color. I have try this way... @Html.DisplayFor(modelItem=>System.Drawing.ColorTranslator.FromHtml(item.color)) But this not working. item.Color is a value from database and it's like this #ffffff; Any suggestions ? Thanks for help in advance!

        P Offline
        P Offline
        poongunrans
        wrote on last edited by
        #3

        In GridView BackColor='<# System.Drawing.Color.FromName(Eval("item_color").ToString())%>'

        A 1 Reply Last reply
        0
        • A Alem B

          I have some data from model , in which i getting some hex values .. now i need to translate this hex values to real color. I have try this way... @Html.DisplayFor(modelItem=>System.Drawing.ColorTranslator.FromHtml(item.color)) But this not working. item.Color is a value from database and it's like this #ffffff; Any suggestions ? Thanks for help in advance!

          Richard DeemingR Offline
          Richard DeemingR Offline
          Richard Deeming
          wrote on last edited by
          #4

          Alem.B wrote:

          But this not working.

          Define "not working". The only obvious problem with your code is the inconsistent naming in your lambda expression:

          modelItem => System.Drawing.ColorTranslator.FromHtml(item.color)

          This should either be item => ... or ...FromHtml(modelItem.color). Also, is it item.color or item.Color? In C#, the case matters.


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

          A 2 Replies Last reply
          0
          • A Ali Al Omairi Abu AlHassan

            try this

            <span style="display: inline-block; width: 20px; height: 20px; background-color: @item.Color"></span>

            it would display like this:

            Help people,so poeple can help you.

            A Offline
            A Offline
            Alem B
            wrote on last edited by
            #5

            Ali you are the King! Thank you!

            A 1 Reply Last reply
            0
            • Richard DeemingR Richard Deeming

              Alem.B wrote:

              But this not working.

              Define "not working". The only obvious problem with your code is the inconsistent naming in your lambda expression:

              modelItem => System.Drawing.ColorTranslator.FromHtml(item.color)

              This should either be item => ... or ...FromHtml(modelItem.color). Also, is it item.color or item.Color? In C#, the case matters.


              "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

              A Offline
              A Offline
              Alem B
              wrote on last edited by
              #6

              Thnxs for some sahring some intresting info!

              1 Reply Last reply
              0
              • Richard DeemingR Richard Deeming

                Alem.B wrote:

                But this not working.

                Define "not working". The only obvious problem with your code is the inconsistent naming in your lambda expression:

                modelItem => System.Drawing.ColorTranslator.FromHtml(item.color)

                This should either be item => ... or ...FromHtml(modelItem.color). Also, is it item.color or item.Color? In C#, the case matters.


                "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                A Offline
                A Offline
                Alem B
                wrote on last edited by
                #7

                Thnxs for some sharing some intresting info!

                1 Reply Last reply
                0
                • P poongunrans

                  In GridView BackColor='<# System.Drawing.Color.FromName(Eval("item_color").ToString())%>'

                  A Offline
                  A Offline
                  Alem B
                  wrote on last edited by
                  #8

                  Thnxs for info how to do that in WebGrid!

                  1 Reply Last reply
                  0
                  • A Alem B

                    Ali you are the King! Thank you!

                    A Offline
                    A Offline
                    Ali Al Omairi Abu AlHassan
                    wrote on last edited by
                    #9

                    The king of Persia :-D

                    Help people,so poeple can help you.

                    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