gridview question for databinding

Discussion in 'ASP .Net' started by =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?=, Nov 22, 2006.

  1. I am trying to set the text color of a cell in a data grid based on the a
    value from the data source. I believe i should be doing it in
    gridview_RowDataBound, but i do not know how to get to the value in the data
    source. I'll try to explain:

    column X should be red or green based on the value from szCellColor as
    returned from the query used to fill the gridview. However, szCellColor is
    NOT a column in the gridview.

    Does anyone know how i can access this value from the query bound to the
    gridview without the need to make it a hidden colmun?

    Any hel pwould be appreciated

    --
    thanks (as always)
    some day i''m gona pay this forum back for all the help i''m getting
    kes
    =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?=, Nov 22, 2006
    #1
    1. Advertising

  2. =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?=

    Mark Rae Guest

    "WebBuilder451" <> wrote in message
    news:...

    >I am trying to set the text color of a cell in a data grid based on the a
    > value from the data source. I believe i should be doing it in
    > gridview_RowDataBound, but i do not know how to get to the value in the
    > data
    > source. I'll try to explain:
    >
    > column X should be red or green based on the value from szCellColor as
    > returned from the query used to fill the gridview. However, szCellColor is
    > NOT a column in the gridview.
    >
    > Does anyone know how i can access this value from the query bound to the
    > gridview without the need to make it a hidden colmun?


    Yup - all you need is to reference the e.Row.DataItem and cast it to a
    DataRowView object e.g.

    if ((((DataRowView)e.Row.DataItem)["szCellColor"]).ToString() == "red")
    {
    e.Row.Cells[0].ForeColor = System.Drawing.Color.Red;
    }
    else
    {
    e.Row.Cells[0].ForeColor = System.Drawing.Color.Green;
    }
    Mark Rae, Nov 22, 2006
    #2
    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. Daves
    Replies:
    0
    Views:
    1,393
    Daves
    May 10, 2005
  2. =?Utf-8?B?bWdvbnphbGVzMw==?=

    GridView Hierarchical View - Gridview in Gridview

    =?Utf-8?B?bWdvbnphbGVzMw==?=, May 9, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    17,944
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
    May 9, 2006
  3. Sergei Shelukhin
    Replies:
    1
    Views:
    558
    Mark Rae
    Nov 12, 2006
  4. jobs
    Replies:
    0
    Views:
    1,597
  5. Earl Teigrob
    Replies:
    1
    Views:
    388
    Shravan
    Mar 1, 2004
Loading...

Share This Page