-1

Possible Duplicates:
How to alternate HTML table row colors using JSP?
Table row - Giving alternate colors

Can anyone provide basic code for dynamically adding rows in a table with alternate colors using CSS in jsp file kindly provide this code?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • have you tried to [search for your problem](http://stackoverflow.com/search?q=css+alternating+row+color)? – oezi Oct 29 '10 at 16:11

4 Answers4

1
<table>
<?
    boolean evenRow = true;
    for (int i = 0; i < numRowsToDisplay; i++)
    {
?>

<tr class="<?= evenRow? "evenrowstyle" : "oddrowstyle" ?>"><td>whatever</td></tr>

<?
        evenRow = !evenRow;
    }
?>
</table>
Riley Lark
  • 20,660
  • 15
  • 80
  • 128
0

Basically, there are two options:

  • either you have to add a style class to all even (or odd) rows in your jsp
  • or you can do it dynamically on the client with javascript (if that's an option)
Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588
0

Take a look at the CSS odd and even selectors.

Lazarus
  • 41,906
  • 4
  • 43
  • 54
0

as in

<style>
#TableID tr:nt-child(odd){
background-color:white;
}

#TableID tr:nth-child(even){
background-color:silver;
}
</style>
FatherStorm
  • 7,133
  • 1
  • 21
  • 27