locked
How to format a Webgrid column RRS feed

  • Question

  • User170277026 posted

    I have a database table where a column has a float data like 300 for example.

    I need to show that data in a webgrid column as 3.00

    How to do that? how to format webgrid column 

    Any help is highly appreciated.

    Monday, February 2, 2015 2:56 AM

Answers

  • User1713851783 posted

    Try with

    grid.Column(
         columnName : "PPrice",
         header: "Price",
         format: @<text>@((item.PPrice / 100).ToString("0.00"))</text>)
    )

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 2, 2015 7:05 AM

All replies

  • User364480375 posted

    try something like this: roughly code

    @{
    
    string s=((decimal) 
    
    ((decimal)50 / (decimal)102) *100)).ToString("#.00");
    
    }

    Monday, February 2, 2015 4:26 AM
  • User170277026 posted

    Thanx for the reply but I don't get your code.

    I have code like this:

    @grid.GetHtml(    
                alternatingRowStyle : "alternate",
                headerStyle : "header",
                columns: grid.Columns(
                    grid.Column("PID", "ID"),
                    grid.Column("PDescription", "Description"),
                    grid.Column("PPrice", "Price") //<=== How to format this column to convert float 0000 to 00.00
    
                )
            )

    How to format the price column to be in like 20.00 for example instead of 2000 (Note: PPrice is float in SQL Server)

    Monday, February 2, 2015 5:08 AM
  • User1713851783 posted

    Try with

    grid.Column(
         columnName : "PPrice",
         header: "Price",
         format: @<text>@((item.PPrice / 100).ToString("0.00"))</text>)
    )

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 2, 2015 7:05 AM