Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 26th, 2004, 01:56 PM
Registered User
 
Join Date: Feb 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default change background color of cell based on value

I built a very basic asp page that displays the contents of an access database in a table. It is a system status page, so one of the fields is either "UP" or "DOWN". I want to be able to make that cell's background color red when the value is DOWN. Can this be done with ASP?

 
Old February 26th, 2004, 02:04 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

It's not a question of ASP, but of HTML.

Either set the table cell's background color:
<td bgcolor="#FF0000"></td>

Or you could use inline styles:
<td style="background-color:#FF0000;"></td>

Or you could use CSS:
<style>
TD.down{ background-color:#FF0000; }
</style>
<td class="down"></td>

I'd recommend using CSS as this is more standard and would reduce the overall HTML weight of your page.

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old February 26th, 2004, 02:06 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Then again, I just noticed this is in the ASPX forum. Are you using a datalist/grid for your data display? That would change things a bit.
 
Old February 26th, 2004, 02:20 PM
Registered User
 
Join Date: Feb 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes I am using a html table to display the data. I know how to change the color, but I only want to change the color when the value is DOWN. I.E. if the value is up, leave the color alone.

 
Old February 26th, 2004, 03:52 PM
Registered User
 
Join Date: Feb 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I figured it out. Just a basic if then statement works fine:

<% if rs.("field1") = "UP" then %>
<td><% = ("field1") %></td>
<% else %>
<td bgcolor="red"><% = ("field1") %></td>
<% end if %>







Similar Threads
Thread Thread Starter Forum Replies Last Post
Change background color using CSS pigtail Javascript How-To 9 April 4th, 2010 11:13 AM
change color of background meena88 C# 2005 3 December 1st, 2009 04:48 AM
change background color of inputbox vickriz Javascript How-To 3 December 1st, 2009 02:22 AM
Change the background color of a msgbox nobreferreira VB.NET 2002/2003 Basics 3 October 28th, 2004 09:37 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.