Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Change style of a single row of the item list of datagrid, based on a field value of current item...

Reply
Thread Tools

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

 
 
QUASAR
Guest
Posts: n/a
 
      01-14-2004
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!


 
Reply With Quote
 
 
 
 
Alvin Bruney
Guest
Posts: n/a
 
      01-14-2004
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...
http://tinyurl.com/3he3b
"QUASAR" <> wrote in message
news:...
> 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!
>
>



 
Reply With Quote
 
 
 
 
QUASAR
Guest
Posts: n/a
 
      01-15-2004
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$...
> 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...
> http://tinyurl.com/3he3b
> "QUASAR" <> wrote in message
> news:...
> > 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!
> >
> >

>
>



 
Reply With Quote
 
Alvin Bruney
Guest
Posts: n/a
 
      01-15-2004
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...
http://tinyurl.com/3he3b
"QUASAR" <> wrote in message
news:%...
> 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$...
> > 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...
> > http://tinyurl.com/3he3b
> > "QUASAR" <> wrote in message
> > news:...
> > > 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!
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
QUASAR
Guest
Posts: n/a
 
      01-16-2004
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##...
> 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...
> http://tinyurl.com/3he3b
> "QUASAR" <> wrote in message
> news:%...
> > 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$...
> > > 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...
> > > http://tinyurl.com/3he3b
> > > "QUASAR" <> wrote in message
> > > news:...
> > > > 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!
> > > >
> > > >
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
QUASAR
Guest
Posts: n/a
 
      01-17-2004
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" <> ha scritto nel messaggio
news:...
> 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!
>
>



 
Reply With Quote
 
QUASAR
Guest
Posts: n/a
 
      01-17-2004
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
<aspataGrid 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" <> ha scritto nel messaggio
news:...
> 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!
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
javascript validation for a not required field, field is onlyrequired if another field has a value jr Javascript 3 07-08-2010 10:33 AM
How to change the style for the row while mouse over the cell of that row? Cylix Javascript 0 06-13-2006 11:06 AM
Gridview - Accessing a field value in current row Joe Reiss ASP .Net Web Controls 3 01-04-2006 07:44 PM
Need help with Style conversion from Style object to Style key/value collection. Ken Varn ASP .Net Building Controls 0 04-26-2004 07:06 PM
If value in name field in top row disable submit button until add button is pressed or field is cleared. Chuck Javascript 0 11-10-2003 02:23 AM



Advertisments
 



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