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

Ask a Question related to ASP.NET Data Grid Control, Design and Development.

  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. Similar Questions and Discussions

    1. Cannot change datagrid item background colourdynamically
      Hello, I am trying to change the background colour of a data grid item dynamically. I am using a component for each item with the item_renderer...
    2. datagrid checkbox list edit item not working
      I am using asp template columns. I display box values from a lookup table. The datagrid displays field "bookid" and the checkbox displays...
    3. Single item Array Problem
      Hi, I have a XML file like this: ... <pdpCategory name="Acute Illness"> <pdpMeasure name = "First Line Antibiotics">...
    4. How to set selected item in drop-down list in datagrid
      Donald Welker wrote: SelectedValue='<%# DataBinder.Eval(Container.DataItem,"ABCField") %>' -- Jos
    5. Add single item to number of files in one step
      Several FAX/DOCUMENT managing programs make multi-page TIFFs. Even the Windows Imaging proggie that shipped with Windows 9x does. Mac
  3. #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" <gz77@tiscali.it> wrote in message
    news:OVgy5Gu2DHA.2548@tk2msftngp13.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

  4. #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.3140@tk2msftngp13.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" <gz77@tiscali.it> wrote in message
    > news:OVgy5Gu2DHA.2548@tk2msftngp13.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

  5. #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" <gz77@tiscali.it> wrote in message
    news:%23BZpixv2DHA.1740@TK2MSFTNGP09.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.3140@tk2msftngp13.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" <gz77@tiscali.it> wrote in message
    > > news:OVgy5Gu2DHA.2548@tk2msftngp13.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

  6. #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.2460@TK2MSFTNGP10.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" <gz77@tiscali.it> wrote in message
    > news:%23BZpixv2DHA.1740@TK2MSFTNGP09.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.3140@tk2msftngp13.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" <gz77@tiscali.it> wrote in message
    > > > news:OVgy5Gu2DHA.2548@tk2msftngp13.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. #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" <gz77@tiscali.it> ha scritto nel messaggio
    news:OVgy5Gu2DHA.2548@tk2msftngp13.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

  8. #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" <gz77@tiscali.it> ha scritto nel messaggio
    news:OVgy5Gu2DHA.2548@tk2msftngp13.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

Posting Permissions

  • You may not post new threads
  • You may 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