Adding BackGround Colors to a data table

C

colo

This is a newbie question...

I have a webpage that is showing info from a database using a GridView
control. The problem is that I want to color specific Column in
different colors. For example...

Student Name - Grade - Quartile
John - 89 - 1
Lucy - 68 - 3
Mike - 89 - 1
Susy - 75 - 2
etc..

So for the Quartile Column I want to be able to color the cells that
have 1s in green, 2s in yellow, 3s in blue, etc... is this possible?

Thanks!!!
 
E

Eliyahu Goldin

Sure. You need to handle the grid's RowDataBound event. It fires for every
row. You get a reference to the row as an event parameter. You can check the
text value of the cell for Quartile and set it's background color
accordingly.
 
C

colo

Thanks Eliyahu

I tried:
If e.Row.RowType = DataControlRowType.DataRow Then
If e.Row.Cells(1).Text = "1" Then e.Row.Cells(1).BackColor
= Drawing.Color.Blue
If e.Row.Cells(1).Text = "2" Then e.Row.Cells(1).BackColor
= Drawing.Color.Red
If e.Row.Cells(1).Text = "3" Then e.Row.Cells(1).BackColor
= Drawing.Color.Yellow

End If

and it worked fine!!!


Eliyahu said:
Sure. You need to handle the grid's RowDataBound event. It fires for every
row. You get a reference to the row as an event parameter. You can check the
text value of the cell for Quartile and set it's background color
accordingly.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin


colo said:
This is a newbie question...

I have a webpage that is showing info from a database using a GridView
control. The problem is that I want to color specific Column in
different colors. For example...

Student Name - Grade - Quartile
John - 89 - 1
Lucy - 68 - 3
Mike - 89 - 1
Susy - 75 - 2
etc..

So for the Quartile Column I want to be able to color the cells that
have 1s in green, 2s in yellow, 3s in blue, etc... is this possible?

Thanks!!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top