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. Advertising

  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. Advertising

  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. Advertising

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. Not Me
    Replies:
    0
    Views:
    486
    Not Me
    Sep 23, 2005
  2. Willem
    Replies:
    5
    Views:
    1,051
    David Dorward
    Oct 4, 2004
  3. =?Utf-8?B?QWxleCBNYWdoZW4=?=

    Formatting Values in DataGrid Control

    =?Utf-8?B?QWxleCBNYWdoZW4=?=, Jun 9, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    537
    Winista
    Jun 11, 2006
  4. Keith G Hicks
    Replies:
    5
    Views:
    394
    Keith G Hicks
    Apr 8, 2008
  5. hangar18
    Replies:
    0
    Views:
    133
    hangar18
    Mar 22, 2006
Loading...

Share This Page