【发布时间】:2014-06-16 21:01:40
【问题描述】:
我正在使用剃须刀视图引擎使用 ASP.NET c# 开发一个网站。我正在使用 for 循环来显示数据库中的行并将其显示在 html 表中。每行包含一个名为“requestStatus”的变量。请求状态为“已批准”、“已拒绝”或待处理。有没有办法可以根据 requeststatus 更改表格行的 bg 颜色,例如,如果 requeststatus 为“待处理”,则将表格行设置为黄色,如果请求状态为“已批准”,则将表格行 bgcolor 设置为绿色?
任何帮助都会非常棒!
我使用的代码显示表格如下
<fieldset>
<legend>Your Leave Requests</legend>
<table border="1" width="100%">
<tr bgcolor="grey">
<th>Description</th>
<th>Leave Type</th>
<th>Start Date</th>
<th>End Date</th>
<th>Total days leave requested</th>
<th>Request Status</th>
</tr>
@foreach(var rows2 in rows1){
<tr>
<th>@rows2.description</th>
<th>@rows2.leaveType</th>
<th>@rows2.startDate.ToString("dd-MMMM-yyyy")</th>
<th>@rows2.endDate.ToString("dd-MMMM-yyyy")</th>
<th>@rows2.totalDays</th>
<th>@rows2.requestStatus</th>
</tr>
}
</table>
</fieldset>
【问题讨论】: