Reputation: 12619
I'm overthinking this. I have colors stored in a database table, and I want to set the background of specific cells in a table to those colors. In other words:
<table>
<tr>
<td ???set color here???>
...content...
</td>
<td ???next color here???>
...next content...
</td>
</tr>
</table>
Originally I had Panels surrounding each piece of content and I set their background color in the code-behind, which worked fine until I had varying size panels, which threw off the layout. What's the easiest way to feed the color values from the database to the <td>
element? Note that the colors are user-configurable, so I can't have them pre-defined in a CSS file.
Upvotes: 0
Views: 2050
Reputation: 2358
You could output a css file fromt the database when the application starts up, and then include the css file in the master page.
Upvotes: 0
Reputation: 33474
Is this a table with fixed number of rows/columns?
You might use ASP style of code here.
td backcolor="<%= MyColorProvider.FirstCellColor %>" .....
Where MyColorProvider.FirstCellColor is the string representation of color (it could be a hex string as well).
Upvotes: 0
Reputation: 6808
You can make a custom CSS file with database data by creating a custom HttpHandler.
But the simple way woud be:
<td style="background-color:#000000">
...
</td>
with
<td style='background-color:<%= GetCellColor() %>'>
...
</td>
Upvotes: 7
Reputation: 114417
Why not have the DB populate the CSS?
.dark {
background-color:[database field]
}
<td class='dark'></td>
Upvotes: 0