I am using the MVC3 WebGrid (Razor) and everything is working fine. However, I need to vary the css class that is attached to a particular column based on the value that is in the column.
I have a non-Server-side JQuery way of doing this already. There are a few reasons why I want this to happen outside of JQuery.
Basically, I'm doing cell traffic-lighting/highlighting based on the value of the cell. So if the value in the cell is "62.5", the class that needs to be attached to the <td>
is scr60
. This sets the background-color for the cell to the appropriate shade.
<tr>
<td class="scr60">62.5</td>
</tr>
I know I can control the output of the contents of the cell using the format:
parameter on the grid.Column()
definition, but I need to set the CSS class for the actual <td>
that contains the contents (so that the entire cell is highlighted, not just the value/content itself.
I already have a separate helper class/method to output the name of the CSS class I want to use, based on the value. What I need is a way to adjust the style of the containing <td>
using the output of that method.
Again, I already have a JQuery solution that does this, I'm looking for a way to do this with the webgrid itself.