Professional Web Applications Themes

Change style of a single row of the item list of datagrid, based on a field value of current item... - ASP.NET Data Grid Control

Sorry for the long subject guys, but I don't know how better I can resume the matter... Anyway, I have my datagrid showing items of an order. I want to have different backcolor of the rows based on the value of the ItemType field of the current item (datagrid row)... Example, if the current item (datagrid row) ItemType filed value is 1 i wanna have this row backcolor red, if 2 then yellow, and so on... Was very clear how to do this in classic asp but now using the datagrid control nomore... I know I can use a datalist ...

  1. #1

    Default Change style of a single row of the item list of datagrid, based on a field value of current item...

    Sorry for the long subject guys, but I don't know how better I can resume
    the matter...

    Anyway, I have my datagrid showing items of an order.
    I want to have different backcolor of the rows based on the value of the
    ItemType field of the current item (datagrid row)...
    Example, if the current item (datagrid row) ItemType filed value is 1 i
    wanna have this row backcolor red, if 2 then yellow, and so on...
    Was very clear how to do this in classic asp but now using the datagrid
    control nomore...
    I know I can use a datalist that is more flexible, but I wanna use datagrid
    :)

    Thanks! ;)


    QUASAR Guest

  2. #2

    Default Re: Change style of a single row of the item list of datagrid, based on a field value of current item...

    trap the itemdatabound event
    if(e.item.listitemtype == listitemtype.item or alternateitem)
    e.item.cells[0].BackColor = System.Drawing.Color.Red;

    roughly

    --
    Regards,
    Alvin Bruney
    Got tidbits? Get it here...
    [url]http://tinyurl.com/3he3b[/url]
    "QUASAR" <gz77tiscali.it> wrote in message
    news:OVgy5Gu2DHA.2548tk2msftngp13.phx.gbl...
    > Sorry for the long subject guys, but I don't know how better I can resume
    > the matter...
    >
    > Anyway, I have my datagrid showing items of an order.
    > I want to have different backcolor of the rows based on the value of the
    > ItemType field of the current item (datagrid row)...
    > Example, if the current item (datagrid row) ItemType filed value is 1 i
    > wanna have this row backcolor red, if 2 then yellow, and so on...
    > Was very clear how to do this in classic asp but now using the datagrid
    > control nomore...
    > I know I can use a datalist that is more flexible, but I wanna use
    datagrid
    > :)
    >
    > Thanks! ;)
    >
    >

    Alvin Bruney Guest

  3. #3

    Default Re: Change style of a single row of the item list of datagrid, based on a field value of current item...

    Alvin thanks a lot.
    I suppose the code given is C wich is not familiar to me (i'm a really newby
    :) )
    Can you detail a bit more in VB ?

    Thanks,
    Quasar ;)

    "Alvin Bruney" <vapor at steaming post office> ha scritto nel messaggio
    news:uR3$KKu2DHA.3140tk2msftngp13.phx.gbl...
    > trap the itemdatabound event
    > if(e.item.listitemtype == listitemtype.item or alternateitem)
    > e.item.cells[0].BackColor = System.Drawing.Color.Red;
    >
    > roughly
    >
    > --
    > Regards,
    > Alvin Bruney
    > Got tidbits? Get it here...
    > [url]http://tinyurl.com/3he3b[/url]
    > "QUASAR" <gz77tiscali.it> wrote in message
    > news:OVgy5Gu2DHA.2548tk2msftngp13.phx.gbl...
    > > Sorry for the long subject guys, but I don't know how better I can
    resume
    > > the matter...
    > >
    > > Anyway, I have my datagrid showing items of an order.
    > > I want to have different backcolor of the rows based on the value of the
    > > ItemType field of the current item (datagrid row)...
    > > Example, if the current item (datagrid row) ItemType filed value is 1 i
    > > wanna have this row backcolor red, if 2 then yellow, and so on...
    > > Was very clear how to do this in classic asp but now using the datagrid
    > > control nomore...
    > > I know I can use a datalist that is more flexible, but I wanna use
    > datagrid
    > > :)
    > >
    > > Thanks! ;)
    > >
    > >
    >
    >

    QUASAR Guest

  4. #4

    Default Re: Change style of a single row of the item list of datagrid, based on a field value of current item...

    from a scott mitchell article

    Sub ItemDataBoundEventHandler(sender as Object, e as DataGridItemEventArgs)
    If e.Item.ItemType = ListItemType.Item OR _
    e.Item.ItemType = ListItemType.AlternatingItem then
    'Check to see if the price is below a certain threshold
    Dim price as Double
    price = Convert.ToDouble(DataBinder.Eval(e.Item.DataItem, "price"))

    If price < 10.0 then
    e.Item.BackColor = System.Drawing.Color.Yellow
    End If
    End If
    End Sub


    --
    Regards,
    Alvin Bruney
    Got tidbits? Get it here...
    [url]http://tinyurl.com/3he3b[/url]
    "QUASAR" <gz77tiscali.it> wrote in message
    news:%23BZpixv2DHA.1740TK2MSFTNGP09.phx.gbl...
    > Alvin thanks a lot.
    > I suppose the code given is C wich is not familiar to me (i'm a really
    newby
    > :) )
    > Can you detail a bit more in VB ?
    >
    > Thanks,
    > Quasar ;)
    >
    > "Alvin Bruney" <vapor at steaming post office> ha scritto nel messaggio
    > news:uR3$KKu2DHA.3140tk2msftngp13.phx.gbl...
    > > trap the itemdatabound event
    > > if(e.item.listitemtype == listitemtype.item or alternateitem)
    > > e.item.cells[0].BackColor = System.Drawing.Color.Red;
    > >
    > > roughly
    > >
    > > --
    > > Regards,
    > > Alvin Bruney
    > > Got tidbits? Get it here...
    > > [url]http://tinyurl.com/3he3b[/url]
    > > "QUASAR" <gz77tiscali.it> wrote in message
    > > news:OVgy5Gu2DHA.2548tk2msftngp13.phx.gbl...
    > > > Sorry for the long subject guys, but I don't know how better I can
    > resume
    > > > the matter...
    > > >
    > > > Anyway, I have my datagrid showing items of an order.
    > > > I want to have different backcolor of the rows based on the value of
    the
    > > > ItemType field of the current item (datagrid row)...
    > > > Example, if the current item (datagrid row) ItemType filed value is 1
    i
    > > > wanna have this row backcolor red, if 2 then yellow, and so on...
    > > > Was very clear how to do this in classic asp but now using the
    datagrid
    > > > control nomore...
    > > > I know I can use a datalist that is more flexible, but I wanna use
    > > datagrid
    > > > :)
    > > >
    > > > Thanks! ;)
    > > >
    > > >
    > >
    > >
    >
    >

    Alvin Bruney Guest

  5. #5

    Default Re: Change style of a single row of the item list of datagrid, based on a field value of current item...

    Thanks Alvin, I've tried but doesn't work... I give you here my code for the
    sub...
    What goes wrong?
    Can you give me a link to the article of Scott Mitchell you mention?

    Thanks, Giorgio.
    ----------------------------------------------------------------------------
    ---------

    Sub ItemDataBoundEventHandler(sender as Object, e as
    DataGridItemEventArgs)
    If e.Item.ItemType = ListItemType.Item OR _
    e.Item.ItemType = ListItemType.AlternatingItem then
    'Check to see if the genre ID is 1 (Ancillary)
    Dim genre As String
    genre = (DataBinder.Eval(e.Item.DataItem, "_ID_genre"))

    If genre > 1 then
    e.Item.BackColor = System.Drawing.Color.Yellow
    End If
    End If
    End Sub

    '---------------------------------------------------------------------------
    ----------

    "Alvin Bruney" <vapor at steaming post office> ha scritto nel messaggio
    news:ulT##542DHA.2460TK2MSFTNGP10.phx.gbl...
    > from a scott mitchell article
    >
    > Sub ItemDataBoundEventHandler(sender as Object, e as
    DataGridItemEventArgs)
    > If e.Item.ItemType = ListItemType.Item OR _
    > e.Item.ItemType = ListItemType.AlternatingItem then
    > 'Check to see if the price is below a certain threshold
    > Dim price as Double
    > price = Convert.ToDouble(DataBinder.Eval(e.Item.DataItem, "price"))
    >
    > If price < 10.0 then
    > e.Item.BackColor = System.Drawing.Color.Yellow
    > End If
    > End If
    > End Sub
    >
    >
    > --
    > Regards,
    > Alvin Bruney
    > Got tidbits? Get it here...
    > [url]http://tinyurl.com/3he3b[/url]
    > "QUASAR" <gz77tiscali.it> wrote in message
    > news:%23BZpixv2DHA.1740TK2MSFTNGP09.phx.gbl...
    > > Alvin thanks a lot.
    > > I suppose the code given is C wich is not familiar to me (i'm a really
    > newby
    > > :) )
    > > Can you detail a bit more in VB ?
    > >
    > > Thanks,
    > > Quasar ;)
    > >
    > > "Alvin Bruney" <vapor at steaming post office> ha scritto nel messaggio
    > > news:uR3$KKu2DHA.3140tk2msftngp13.phx.gbl...
    > > > trap the itemdatabound event
    > > > if(e.item.listitemtype == listitemtype.item or alternateitem)
    > > > e.item.cells[0].BackColor = System.Drawing.Color.Red;
    > > >
    > > > roughly
    > > >
    > > > --
    > > > Regards,
    > > > Alvin Bruney
    > > > Got tidbits? Get it here...
    > > > [url]http://tinyurl.com/3he3b[/url]
    > > > "QUASAR" <gz77tiscali.it> wrote in message
    > > > news:OVgy5Gu2DHA.2548tk2msftngp13.phx.gbl...
    > > > > Sorry for the long subject guys, but I don't know how better I can
    > > resume
    > > > > the matter...
    > > > >
    > > > > Anyway, I have my datagrid showing items of an order.
    > > > > I want to have different backcolor of the rows based on the value of
    > the
    > > > > ItemType field of the current item (datagrid row)...
    > > > > Example, if the current item (datagrid row) ItemType filed value is
    1
    > i
    > > > > wanna have this row backcolor red, if 2 then yellow, and so on...
    > > > > Was very clear how to do this in classic asp but now using the
    > datagrid
    > > > > control nomore...
    > > > > I know I can use a datalist that is more flexible, but I wanna use
    > > > datagrid
    > > > > :)
    > > > >
    > > > > Thanks! ;)
    > > > >
    > > > >
    > > >
    > > >
    > >
    > >
    >
    >

    QUASAR Guest

  6. #6

    Default Re: Change style of a single row of the item list of datagrid, based on a field value of current item...

    Change color of a single row of the item list of datagrid, based on a field
    value of current item...

    Now I'm trying with this code but without success again :((
    What is wrong?
    No one can help???

    Thanks :)

    '---------------------------------------------------------------------------
    Sub ItemGrid_ItemDataBound(ByVal source As Object, ByVal e As
    DataGridItemEventArgs)
    ' OR ALSO I'VE TRYED Sub ItemGrid_ItemDataBound(sender as Object, e as
    DataGridItemEventArgs)

    If (e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
    ListItemType.AlternatingItem) Then

    If e.Item.DataItem("_ID_genre") < 2 Then
    ' genre is "ancillary equipment"
    e.Item.BackColor = System.Drawing.Color.Yellow
    e.Item.Cells.Item(0).BackColor =
    System.Drawing.Color.FromName("Green")
    End If

    End If

    End Sub

    '---------------------------------------------------------------------------


    "QUASAR" <gz77tiscali.it> ha scritto nel messaggio
    news:OVgy5Gu2DHA.2548tk2msftngp13.phx.gbl...
    > Sorry for the long subject guys, but I don't know how better I can resume
    > the matter...
    >
    > Anyway, I have my datagrid showing items of an order.
    > I want to have different backcolor of the rows based on the value of the
    > ItemType field of the current item (datagrid row)...
    > Example, if the current item (datagrid row) ItemType filed value is 1 i
    > wanna have this row backcolor red, if 2 then yellow, and so on...
    > Was very clear how to do this in classic asp but now using the datagrid
    > control nomore...
    > I know I can use a datalist that is more flexible, but I wanna use
    datagrid
    > :)
    >
    > Thanks! ;)
    >
    >

    QUASAR Guest

  7. #7

    Default Re: Change style of a single row of the item list of datagrid, based on a field value of current item...

    Ok now it works...
    was my fault, I've not setted in the datagrid properties the
    "OnItemDataBound" event...


    If someone may have the same need the final code was here...
    Insert the sub and don't forgot to set in the datagrid properties the
    "OnItemDataBound" event
    <asp:DataGrid id="DataGrid1"...
    ....OnItemDataBound="DataGrid1_ItemDataBoundEvent"

    '---------------------------------------------------------------------------
    ----------

    Sub DataGrid1_ItemDataBoundEvent(sender as Object, e as
    DataGridItemEventArgs)

    If e.Item.ItemType = ListItemType.Item _
    OR e.Item.ItemType = ListItemType.AlternatingItem then

    'Check to see if the genre ID is 1 (Ancillary)
    If e.Item.DataItem("_ID_Tipo_Item") < 2 Then
    e.Item.BackColor = System.Drawing.Color.FromName("Lavender")
    End If

    End If

    End Sub

    '---------------------------------------------------------------------------
    ----------

    Byez,
    Giorgio


    "QUASAR" <gz77tiscali.it> ha scritto nel messaggio
    news:OVgy5Gu2DHA.2548tk2msftngp13.phx.gbl...
    > Sorry for the long subject guys, but I don't know how better I can resume
    > the matter...
    >
    > Anyway, I have my datagrid showing items of an order.
    > I want to have different backcolor of the rows based on the value of the
    > ItemType field of the current item (datagrid row)...
    > Example, if the current item (datagrid row) ItemType filed value is 1 i
    > wanna have this row backcolor red, if 2 then yellow, and so on...
    > Was very clear how to do this in classic asp but now using the datagrid
    > control nomore...
    > I know I can use a datalist that is more flexible, but I wanna use
    datagrid
    > :)
    >
    > Thanks! ;)
    >
    >

    QUASAR Guest

Similar Threads

  1. Cannot change datagrid item background colourdynamically
    By WeWeaveDean in forum Macromedia Flex General Discussion
    Replies: 0
    Last Post: June 22nd, 11:33 PM
  2. datagrid checkbox list edit item not working
    By cindy in forum ASP.NET Data Grid Control
    Replies: 1
    Last Post: October 19th, 03:39 AM
  3. Single item Array Problem
    By drkshih in forum Macromedia Flex General Discussion
    Replies: 1
    Last Post: July 15th, 08:38 PM
  4. How to set selected item in drop-down list in datagrid
    By Jos in forum ASP.NET Building Controls
    Replies: 0
    Last Post: August 20th, 07:46 AM
  5. Add single item to number of files in one step
    By Mac McDougald in forum Adobe Photoshop 7, CS, CS2 & CS3
    Replies: 0
    Last Post: June 26th, 01:39 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139