473,387 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Adding BackGround Colors to a data table

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!!!

Dec 20 '06 #1
2 2069
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" <ma************@gmail.comwrote in message
news:11**********************@i12g2000cwa.googlegr oups.com...
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!!!

Dec 20 '06 #2
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 Goldin wrote:
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" <ma************@gmail.comwrote in message
news:11**********************@i12g2000cwa.googlegr oups.com...
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!!!
Dec 20 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Scott | last post by:
There is a setting in IE for "Print background colors and images." I've noticed that without checking this option, a web page will print CSS lines between table rows, but a background color of...
3
by: Bob - Andover, MA | last post by:
I know how to define a background color for the entire page, and for a table, and even using style sheets and 'P CLASS=...' for changing paragraph background colors. However, I'd like to be able...
25
by: Neal | last post by:
According to the CSS lint at http://htmlhelp.org/tools/csscheck/, "The shorthand background property is more widely supported than background-color." Can anyone point me to, or provide, information...
3
by: Peter Williams | last post by:
Hi All, I want to write some javascript for a html page which does the following. Imagine that the page contains a table with 2 columns and 3 rows, e.g.: +---+---+ | A | B | +---+---+
3
by: Vam | last post by:
Hi, My program makes an HTML report which needs to be easily printable. On this report is a table, and one of the columns in the table needs to express a color. I've done this by setting the...
4
by: Franklin | last post by:
WITHOUT KNOWING ANYTHING ABOUT THE CURRENT COLORS, I want to swap the foreground/background colors of a link when someone hovers over it. Is this possible with HTML, CSS, DOM, & JavaScript? If...
10
by: Bob Bedford | last post by:
I've a table in wich I've this CSS: ..oddrow{background-color:#FFFFFF} ..evenrow{background-color:#CCCCCC} The oddrows are white and the even are grey. BUT ! when I do print the table,...
2
by: shapper | last post by:
Hello, How can add a background color to each table cell in a table header and also add a small image on the bottom right corner of each of those cells? Thanks, Miguel
1
by: rahees | last post by:
Hi all, Can anybody help me to print the repeater data from asp.net page? I am binding two columns of the repeater table. It is including the background color, which is fetching from the database....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.