dynamically changing row color in a datagrid

Discussion in 'ASP .Net' started by Sonny Sablan, Apr 2, 2006.

  1. Sonny Sablan

    Sonny Sablan Guest

    I would like to dynamically change the row color in a datagrid...

    I have a list (from a db) where users can mark certain records. When they
    are marked I want to display the row in the specified color of the user. i.e
    Joe = BLUE, Ed = YELLOW, etc. All other rows can be set to NO COLOR.

    I cannot seem to find a way to do this with the web control. Can you help?

    Sonny
     
    Sonny Sablan, Apr 2, 2006
    #1
    1. Advertising

  2. If you have the color preference of each user saved on a field in your
    datatable that you bound to the datagrid then you can handle the
    ItemDataBound event to change the color or each row like this:

    protected void DataGrid1_ItemDataBound(object sender,
    System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
    if (e.Item.ItemType == ListItemType.Item ||
    e.Item.ItemType == ListItemType.AlternatingItem)
    {

    e.Item.Style.Add("background-color",((DataRowView)e.Item.DataItem)["UserPreferredColor"]);
    }
    }

    --
    HTH,
    Phillip Williams
    http://www.societopia.net
    http://www.webswapp.com


    "Sonny Sablan" wrote:

    > I would like to dynamically change the row color in a datagrid...
    >
    > I have a list (from a db) where users can mark certain records. When they
    > are marked I want to display the row in the specified color of the user. i.e
    > Joe = BLUE, Ed = YELLOW, etc. All other rows can be set to NO COLOR.
    >
    > I cannot seem to find a way to do this with the web control. Can you help?
    >
    > Sonny
    >
    >
    >
    >
     
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=, Apr 2, 2006
    #2
    1. Advertising

  3. Sonny Sablan

    Sonny Sablan Guest

    Thanks...

    How would the WebControl look?

    Sonny


    "Phillip Williams" <> wrote in message
    news:...
    > If you have the color preference of each user saved on a field in your
    > datatable that you bound to the datagrid then you can handle the
    > ItemDataBound event to change the color or each row like this:
    >
    > protected void DataGrid1_ItemDataBound(object sender,
    > System.Web.UI.WebControls.DataGridItemEventArgs e)
    > {
    > if (e.Item.ItemType == ListItemType.Item ||
    > e.Item.ItemType == ListItemType.AlternatingItem)
    > {
    >
    > e.Item.Style.Add("background-color",((DataRowView)e.Item.DataItem)["UserPreferredColor"]);
    > }
    > }
    >
    > --
    > HTH,
    > Phillip Williams
    > http://www.societopia.net
    > http://www.webswapp.com
    >
    >
    > "Sonny Sablan" wrote:
    >
    >> I would like to dynamically change the row color in a datagrid...
    >>
    >> I have a list (from a db) where users can mark certain records. When they
    >> are marked I want to display the row in the specified color of the user.
    >> i.e
    >> Joe = BLUE, Ed = YELLOW, etc. All other rows can be set to NO COLOR.
    >>
    >> I cannot seem to find a way to do this with the web control. Can you
    >> help?
    >>
    >> Sonny
    >>
    >>
    >>
    >>
     
    Sonny Sablan, Apr 3, 2006
    #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. =?Utf-8?B?TmVpbA==?=

    DataGrid, changing background color of a Row?

    =?Utf-8?B?TmVpbA==?=, Oct 7, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    675
    =?Utf-8?B?TmVpbA==?=
    Oct 7, 2004
  2. G. Whiz
    Replies:
    1
    Views:
    2,890
  3. =?Utf-8?B?aWdvdHlvdXJkb3RuZXQ=?=

    change row color of empty row

    =?Utf-8?B?aWdvdHlvdXJkb3RuZXQ=?=, Oct 19, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    461
    Walter Wang [MSFT]
    Oct 24, 2006
  4. raoof ahmed khan

    Changing alternate row color on mouseover

    raoof ahmed khan, May 14, 2008, in forum: ASP .Net
    Replies:
    1
    Views:
    1,708
    Eliyahu Goldin
    May 14, 2008
  5. Kamaljeet Saini
    Replies:
    0
    Views:
    477
    Kamaljeet Saini
    Feb 13, 2009
Loading...

Share This Page