开发者

Apply css to table td accrording to the data from database

开发者 https://www.devze.com 2023-03-08 22:50 出处:网络
I am using asp.net mvc 3, .net 4.0. One of the td in the table has to have a backg开发者_高级运维round colour depending on the data from database. For example, if status is open then yellow, if in pro

I am using asp.net mvc 3, .net 4.0. One of the td in the table has to have a backg开发者_高级运维round colour depending on the data from database. For example, if status is open then yellow, if in progress then green, if closed then blue and so on. I would like to write some extension method to do this. But I am clueless about how do I do it. If anyone could give an example of doing this it would be a great help.

Thanks in advance.


I would recommend you put it in the model associated with the view. So you might have a Boolean property called IsImportant on your model class which makes the table red vs white or something.

Then, in your view (razor?), do like this:

<html>
<body>
<table class="@(Model.IsImportant? "important_table" : "normal_table")">
<!-- ... -->
</table>
</body>
</html>

with the obvious CSS styles:

.important_table
{
  background-color: red;
}

.normal_table
{
  background-color: white;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消