Datagrid - Formatting based on values

Discussion in 'ASP .Net' started by Simon Harris, Feb 7, 2005.

  1. Simon Harris

    Simon Harris Guest

    Hi All,

    I wish to change the background colour and contents of a datagrid cell based
    on the value of one of the columns on a per row basis. So, for example, if
    column A's value is 1, column 2 should be red with 'No' written in it. If
    column A's value is 0, column 2 should be green with 'Yes' written in it.

    Can anyone advise how I could achieve this? (I know how to display/populate
    the datagrid).

    Thanks,
    Simon.
     
    Simon Harris, Feb 7, 2005
    #1
    1. Advertisements

  2. Simon,

    Most flexible way is to use ItemDataBound event. Event handler gets
    reference to an item which represents the grid row. You have access to the
    item cells (row columns) and can get/set cells properties programmatically.

    Eliyahu

    "Simon Harris" <> wrote in message
    news:%...
    > Hi All,
    >
    > I wish to change the background colour and contents of a datagrid cell

    based
    > on the value of one of the columns on a per row basis. So, for example, if
    > column A's value is 1, column 2 should be red with 'No' written in it. If
    > column A's value is 0, column 2 should be green with 'Yes' written in it.
    >
    > Can anyone advise how I could achieve this? (I know how to

    display/populate
    > the datagrid).
    >
    > Thanks,
    > Simon.
    >
    >
     
    Eliyahu Goldin, Feb 7, 2005
    #2
    1. Advertisements

  3. Simon Harris

    Simon Harris Guest

    Thank you! :)

    "Eliyahu Goldin" <> wrote in message
    news:O$...
    > Simon,
    >
    > Most flexible way is to use ItemDataBound event. Event handler gets
    > reference to an item which represents the grid row. You have access to the
    > item cells (row columns) and can get/set cells properties
    > programmatically.
    >
    > Eliyahu
    >
    > "Simon Harris" <> wrote in message
    > news:%...
    >> Hi All,
    >>
    >> I wish to change the background colour and contents of a datagrid cell

    > based
    >> on the value of one of the columns on a per row basis. So, for example,
    >> if
    >> column A's value is 1, column 2 should be red with 'No' written in it. If
    >> column A's value is 0, column 2 should be green with 'Yes' written in it.
    >>
    >> Can anyone advise how I could achieve this? (I know how to

    > display/populate
    >> the datagrid).
    >>
    >> Thanks,
    >> Simon.
    >>
    >>

    >
    >
     
    Simon Harris, Feb 7, 2005
    #3
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. thegame
    Replies:
    1
    Views:
    1,045
    =?Utf-8?B?ZGlyazQx?=
    Feb 28, 2005
  2. Not Me
    Replies:
    0
    Views:
    588
    Not Me
    Sep 23, 2005
  3. Willem
    Replies:
    5
    Views:
    1,273
    David Dorward
    Oct 4, 2004
  4. =?Utf-8?B?QWxleCBNYWdoZW4=?=

    Formatting Values in DataGrid Control

    =?Utf-8?B?QWxleCBNYWdoZW4=?=, Jun 9, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    595
    Winista
    Jun 11, 2006
  5. Keith G Hicks
    Replies:
    5
    Views:
    566
    Keith G Hicks
    Apr 8, 2008
  6. hangar18
    Replies:
    0
    Views:
    241
    hangar18
    Mar 22, 2006
  7. Nathan Sokalski

    Text-based controls: Formatting as inline elements

    Nathan Sokalski, Sep 20, 2005, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    131
    Lau Lei Cheong
    Sep 20, 2005
  8. JStrummer
    Replies:
    2
    Views:
    256
    Evertjan.
    Aug 27, 2004
Loading...