-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,438
  • 68
  • 55
  • 126
  • 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,324
  • 14
  • 78
  • 124
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
  • 284,665
  • 62
  • 456
  • 576
0

Take a look at the CSS odd and even selectors.

Lazarus
  • 40,266
  • 4
  • 42
  • 54
0

as in

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

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