473,785 Members | 2,317 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2082
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.goo glegroups.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 = DataControlRowT ype.DataRow Then
If e.Row.Cells(1). Text = "1" Then e.Row.Cells(1). BackColor
= Drawing.Color.B lue
If e.Row.Cells(1). Text = "2" Then e.Row.Cells(1). BackColor
= Drawing.Color.R ed
If e.Row.Cells(1). Text = "3" Then e.Row.Cells(1). BackColor
= Drawing.Color.Y ellow

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.goo glegroups.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
8684
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 say the header won't. The below style will display the borders in print preview, but won't display the background color. Does anyone know if it's possible to force background CSS or HTML colors to print without having the user change the default...
3
6582
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 to change background colors on a word-by-word basis, or at least sentence-by-sentence basis. Using a paragraph divider splits up the words or sentences, which is not desired. I want the word to still appear inline with its neighboring words.
25
12945
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 on what browsers have difficulty with the non-shortcut methods of setting background properties?
3
4766
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
5529
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 background of the cells in that column to their colors (which differ from row to row), but those background colors don't print unless a certain option is set in IE, which is apparently off by default. The way we've figured around this is to add a...
4
4098
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 so, how? See my HTML below (or go to my test page at http://fmbbowen.com:39353/misc/Misc.html). I also tried treating ..color as a number and subtracting the current color from 0xFFFFFF but that did not work either. The numerous examples I...
10
7733
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, there is nothing !!! How to print such lines colors ? the main purpose of this table is to be
2
1812
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
2119
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. I am really stucked in this. Some javascript functions not printing the color or the table. My repeater control is below. <asp:Repeater ID="repeaterTT" runat="server"> <HeaderTemplate> <Table border="1px" id="tblTT" cellpadding="0"...
0
9643
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10315
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10083
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5379
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2877
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.