quick datagrid format question

Discussion in 'ASP .Net' started by =?Utf-8?B?Tkg=?=, May 20, 2005.

  1. Hi,

    Is it possible to format the background of rows (or cells) in a datagrid
    based on the value of the data in a particular cell. e.g. I have a datagrid
    of say 21 records, 3 records per day of the week. Is it possible to place a
    background color on the rows based on the day e.g. Monday records have a gray
    background, Tuesday records have a blue background etc.

    Thanks
    Niall
    =?Utf-8?B?Tkg=?=, May 20, 2005
    #1
    1. Advertising

  2. Hi Niall,

    You can do it in datagrid_ItemDataBound event:

    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
    ListItemType.AlternatingItem)
    {
    DateTime date = Convert.ToDateTime(e.Item.Cells[date_field_index].Text);
    if (date.DayOfWeek == DayOfWeek.Monday){
    e.Item.BackColor = Color.Gray;
    }
    }

    HTH

    Elton Wang
    =?Utf-8?B?RWx0b24gVw==?=, May 20, 2005
    #2
    1. Advertising

  3. Thanks Elton.

    Why does Convert.ToString(e.Item.Cells(0).Text) return the column heading
    (in my case its "Day") rather than the values e.g. "Mon", "Tues" etc

    Thanks
    N

    "Elton W" wrote:

    > Hi Niall,
    >
    > You can do it in datagrid_ItemDataBound event:
    >
    > if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
    > ListItemType.AlternatingItem)
    > {
    > DateTime date = Convert.ToDateTime(e.Item.Cells[date_field_index].Text);
    > if (date.DayOfWeek == DayOfWeek.Monday){
    > e.Item.BackColor = Color.Gray;
    > }
    > }
    >
    > HTH
    >
    > Elton Wang
    >
    =?Utf-8?B?Tkg=?=, May 23, 2005
    #3
  4. When e.Item.ItemType = ListItemType.Header, it is "Day". In case
    ListItemType.Item and ListItemType.AlternatingItem, it should have a value
    from data source. How do you bind the data source?

    Elton

    "NH" wrote:

    > Thanks Elton.
    >
    > Why does Convert.ToString(e.Item.Cells(0).Text) return the column heading
    > (in my case its "Day") rather than the values e.g. "Mon", "Tues" etc
    >
    > Thanks
    > N
    >
    > "Elton W" wrote:
    >
    > > Hi Niall,
    > >
    > > You can do it in datagrid_ItemDataBound event:
    > >
    > > if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
    > > ListItemType.AlternatingItem)
    > > {
    > > DateTime date = Convert.ToDateTime(e.Item.Cells[date_field_index].Text);
    > > if (date.DayOfWeek == DayOfWeek.Monday){
    > > e.Item.BackColor = Color.Gray;
    > > }
    > > }
    > >
    > > HTH
    > >
    > > Elton Wang
    > >
    =?Utf-8?B?RWx0b24gVw==?=, May 24, 2005
    #4
    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. TN Bella
    Replies:
    1
    Views:
    2,457
    Edward
    Jun 18, 2004
  2. =?Utf-8?B?UnlhbiBTbWl0aA==?=

    Quick Question - Newby Question

    =?Utf-8?B?UnlhbiBTbWl0aA==?=, Feb 14, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    639
    Iain Norman
    Feb 16, 2005
  3. JKop
    Replies:
    11
    Views:
    857
  4. Replies:
    2
    Views:
    277
    Paul Rubin
    Oct 5, 2005
  5. Roy

    Quick! Simple method for editing a nested datagrid!

    Roy, Jan 25, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    108
Loading...

Share This Page