开发者

How to vary the class of a TD on MVC3 WebGrid generated output?

开发者 https://www.devze.com 2023-03-03 18:24 出处:网络
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 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.


From my experience with WebGrid you can't do this BUT you can include a span within the "cell" and add your class(es) to the span based on whatever condition you want.


Like the 'format:' parameter, there is a 'style:' parameter which you can use like this:

style: "class1 class2"
0

精彩评论

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