Jump to content

How to get different colour?


aic007

Recommended Posts

Hi all.I was wondering that if I have a dinamically generated table (gridview), then how can I get it to have blue colour in the first line and the to automaticly have yellow colour on every second line?Any ideas?Regards.

Link to comment
Share on other sites

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...