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. Conditional changing the backcolor of a DataGrid column

Conditional changing the backcolor of a DataGrid column

Scheduled Pinned Locked Moved ASP.NET
question
4 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.
  • P Offline
    P Offline
    PeteConc
    wrote on last edited by
    #1

    Hello. I have a DataGrid which columns bind to columns in a DataSet. What I want to do is changing the backcolor of the Cell in Column 'A' if it has the value '1'. The definition of my DataGrid is as follows: Column 'A' can have values of '1' or '2'. For the items with the value '1' I want to change it's backcolor. Is there an easy way to accomplish this? Thanks.

    M 1 Reply Last reply
    0
    • P PeteConc

      Hello. I have a DataGrid which columns bind to columns in a DataSet. What I want to do is changing the backcolor of the Cell in Column 'A' if it has the value '1'. The definition of my DataGrid is as follows: Column 'A' can have values of '1' or '2'. For the items with the value '1' I want to change it's backcolor. Is there an easy way to accomplish this? Thanks.

      M Offline
      M Offline
      minhpc_bk
      wrote on last edited by
      #2

      Hi there, You simply create an event handler for the ItemDataBound event of the datagrid, and in the handler you can check which value is bound to the column A then you can decide the backcolor for the Cell. You can also use a data binding expression to do that. Btw, next time you should remember to select the "Do not ..." checkbox, otherwise people cannot see the format of the datagrid.

      A 1 Reply Last reply
      0
      • M minhpc_bk

        Hi there, You simply create an event handler for the ItemDataBound event of the datagrid, and in the handler you can check which value is bound to the column A then you can decide the backcolor for the Cell. You can also use a data binding expression to do that. Btw, next time you should remember to select the "Do not ..." checkbox, otherwise people cannot see the format of the datagrid.

        A Offline
        A Offline
        Anonymous
        wrote on last edited by
        #3

        Thank you very much for your help. It was quite easy with the ItemDataBound event handler. But how can I do it with the databinding expression? (i guess that you mean code inside the aspx file, in the control's arguments)

        M 1 Reply Last reply
        0
        • A Anonymous

          Thank you very much for your help. It was quite easy with the ItemDataBound event handler. But how can I do it with the databinding expression? (i guess that you mean code inside the aspx file, in the control's arguments)

          M Offline
          M Offline
          minhpc_bk
          wrote on last edited by
          #4

          Yes, by the the data binding expression I mean you can use the inline code inside the .aspx web page. You can take a look at the syntax from here: Data Binding Expression Syntax[^] You can provide a snippet of code to check the data bound value in the expression or simply make a call to a method which is responsible for checking that for you. The method can be defined in the code-behind or the .aspx page.

          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