locked
Formatting money in a WebGrid RRS feed

  • Question

  • User1097139691 posted

    I would like to format money in a WebGrid so that it is right-aligned.

    I use this but it's still left-aligned:

    grid.Column("Price", format: @<text>@item.Price.ToString("c")</text>),

    Webgrid

    What code would I insert into the grid.Column to create a right-aligned Price column?

    Wednesday, August 12, 2015 11:35 AM

Answers

  • User281315223 posted

    I believe that you could use the style attribute along with some CSS to handle this :

    grid.Column("Price", format: @<text>@item.Price.ToString("c")</text>, style: "right-align"),

    And then simply define a CSS style that corresponds to that :

    .right-align { text-align: right; }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 12, 2015 1:04 PM

All replies

  • User281315223 posted

    I believe that you could use the style attribute along with some CSS to handle this :

    grid.Column("Price", format: @<text>@item.Price.ToString("c")</text>, style: "right-align"),

    And then simply define a CSS style that corresponds to that :

    .right-align { text-align: right; }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 12, 2015 1:04 PM
  • User1097139691 posted

    Thanks Rion!

    Wednesday, August 12, 2015 9:04 PM