|
Better alternating row colors
|
Email
|
| Submitted on: |
7/9/2004 7:49:07 PM |
| By: |
mike
|
| Level: |
Intermediate |
| User Rating: |
By 7 Users |
| Compatibility: |
ASP (Active Server Pages), HTML, VbScript (browser/client side)
|
| Views: |
13363 |
|
|
|
|
|
Present a simple method for creating tables with alternating row colors.
This article has accompanying files
|
 |
| |
Terms of Agreement:
By using this article, you agree to the following terms...
- You may use
this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
- You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.
- You may link to this article from another website, but ONLY if it is not wrapped in a frame.
- You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.
|
Alternating Row Colors:
Using an array and two variables along with the MOD function
you can create many various effects for alternating row colors in your tables.
The Key is the MOD function, this creates an incrementing loop through the array.
Here's how easy it is; (The two hilighted sections are where the action takes place.)
Dim colorset, i, numcolors
'/--- This is your array of colors to use. -------------\
colorset = split("White,LightGrey,SkyBlue,Yellow",",")
numcolors = ubound(colorset)+1
Do
Response.Write "<TR style=""background:" & colorset(i mod numcolors) & ";"">"
'[-- Add your column data in here --]
Response.Write "</TR>"
i = i + 1 '<-- Increment the counter
Loop
Of course the array could be what ever information you want to cycle through, like class names from a stylesheet, or...
|
|
Download article
Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come
out every day, so no prevention program can catch 100% of them. For your own safety, please:
- Re-scan downloaded files using your personal virus checker before using it.
- NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
If you don't have a virus scanner, you can get one at many places on the net
including:McAfee.com
|
Terms of Agreement:
By using this article, you agree to the following terms...
- You may use
this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
- You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.
- You may link to this article from another website, but ONLY if it is not wrapped in a frame.
- You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.
|
Other 1 submission(s) by this author
|
|
Report Bad Submission
|
Your Vote
|
| |
Other User Comments
|
7/12/2004 2:45:27 AM: Paul Byrne
thats an interesting way of doing it. Thanks. (If this comment was disrespectful, please report it.)
|
7/16/2004 1:28:27 PM:
This is exactly what I have been looking for!
Thanks and keep up the good work. (If this comment was disrespectful, please report it.)
|
7/18/2004 9:00:15 PM:
This is a good idea and very innovative. Taking a simple process and making something that has been the same way for a long time better. I like it! (If this comment was disrespectful, please report it.)
|
7/20/2004 2:49:11 AM:
This is something no one has every done before, I suspect. Well done! 5 from me.
Rae MacLeman (If this comment was disrespectful, please report it.)
|
7/28/2004 6:45:52 AM: Christopher Hansen
Sorry to be the one to tell you this, but it's approaching the end of the month and if you check this you might get excited because it looks like you're in the running to win the Coding Contest. (If this comment was disrespectful, please report it.)
|
7/28/2004 6:48:41 AM: Christopher Hansen
But PSC will just throw you some "Fraud Votes Detected" nonsense unless you happen to have some personal relationship with a judge, sponsor PSC, etc. Sorry to be the one to tell you this. (If this comment was disrespectful, please report it.)
|
7/28/2004 11:50:33 AM: mike
Christopher, I appreciate your concern but, I submitted this code because I felt it was a unique solution with more possibilities than the methods typically employed for this task. Winning this contest was not my goal.
Thanks, Mike (If this comment was disrespectful, please report it.)
|
7/29/2004 2:17:47 AM: Christopher Hansen
I too entered because I wanted to share my solution with others, I just don't want you (like myself) to get excited about your victory and then be crushed with a message of fraud votes. (If this comment was disrespectful, please report it.)
|
7/29/2004 2:19:19 AM: Christopher Hansen
I thought you would be picked up for fraud votes because you recieved several excellent votes for some simple code which is considered 'the norm' for that particular task, sorry. (If this comment was disrespectful, please report it.)
|
9/10/2004 2:43:07 AM: chrisas
Been doing coding for years. And now this! It's one of thoses "Why didn't I think of it!" moments. Thanks for that briliant piece of coding! (If this comment was disrespectful, please report it.)
|
9/10/2004 9:48:23 AM:
Tempting to put this in a function, but I'm wondering if it will slow the page down calling the function several times instead of sticking to the loop, anyone?
s = ""
For i=0 To 30
s = s & ""
s = s & "| "
s = s & " | "
s = s & " "
Next
s = s & " "
Private Function RowColor(intR,aColor)
colorset = split(aColor,",")
numcolors = ubound(colorset)+1
RowColor = colorset(i mod numcolors)
End Function (If this comment was disrespectful, please report it.)
|
9/10/2004 9:54:14 AM: mike
Thanks everyone for your responses. As for the function call. Any decent server in use today should be able to deal with it without any discernible difference. I also assume any decent coder would never send the client a page with huge tables (ie hundreds or thousands of rows). Thats what paging is for. (If this comment was disrespectful, please report it.)
|
9/10/2004 8:22:33 PM:
really simple and very effective way to do the alternate coloring. thanks! (If this comment was disrespectful, please report it.)
|
7/2/2005 10:04:44 AM: Thammapat C.
nice job (If this comment was disrespectful, please report it.)
|
1/16/2008 12:16:09 AM: Harvey Rosero
nice job mike... (If this comment was disrespectful, please report it.)
|
Add Your Feedback
Your feedback will be posted below and an email sent to
the author. Please remember that the author was kind enough to
share this with you, so any criticisms must be stated politely, or they
will be deleted. (For feedback not related to this particular article, please
click here instead.)
To post feedback, first please login.
|