Jump to content

How to get different colour?


Recommended Posts

Usually, while iterating through database entries that I'm putting in the table I calculate the modulus of 2 of the iterating variable, which can only return 0 or 1. Then I can select a color for if it's 0 and another when it's 1:Supposing your page is in PHP

<table><?php$n=0;while($row = mysql_fetch_array($query)) {  if($n%2 == 0) {	$class = "row1";  } else {	$class = "row2";  }  echo "<tr><td class=\"{$class}\">{$row['name']}</td><td class=\"{$class}\">{$row['age']}</td></tr>";  $n++;}?></table>

Then add this to your stylesheet:

.row1 { background-color: blue; }.row2 { background-color: yellow; }

Link to comment
Share on other sites

  • 2 weeks later...

Hi, this worked for me, thanks alot,. Even though I am not using php, I understood the logic, and fortunately it worked.However, I have another problem, if someone could help me, I would be most thankful :-)I get my fields like this:this.gridView.Columns.Add(GetColumn("Mobil nr, arbeid", null, "Mobil", true, true));From this code I will get "Mobil nr" displayed as the text of the field.Is there a way to specify the size (width) of this field only?Regards

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...