Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8668827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:18:37+00:00 2026-06-12T18:18:37+00:00

I am using MS WebMatrix to create a dynamic CSHTML page from data obtained

  • 0

I am using MS WebMatrix to create a dynamic CSHTML page from data obtained from a database. I am using the razor syntax.

I have data being returned to my CSHTML page, but it has trailing digits etc. For example I want to format “123.4568” into “$123.46”

How do I get the result to display in the format I need? I also want to change text colour when a target is reached, etc.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T18:18:38+00:00Added an answer on June 12, 2026 at 6:18 pm

    You can set the format of values in a WebGrid using the format optional argument of the column constructor.

    You could try something like this, where the color of Invoices is red if value > 50 or blue if not

    <html lang="en">
        <head>
            <style>
                .column1 {color: red; font-weight: bold;}
                .column2 {color: blue;}
            </style>
        </head>
        <body>
            <p>@stot1.GetHtml(
                columns:stot1.Columns(
                    stot1.Column(
                        columnName:"Invoices",
                        format:@<text>
                                    <span class=@(item.Invoices > 50 ? "column1" : "column2")>
                                        @item.Invoices.ToString("C")
                                    </span>
                                </text>
                    )
                )
            )</p>
        </body>
    </html>
    

    but I see no reason to use WebGrids in your situation.

    The WebGrid helper renders data from a database with support for paging and sorting, but your query returns only one value and you don’t need either of them.

    Edited

    A better solution is to query the table with the QueryValue method, which returns a single scalar value, and display the value without the WebGrid.

    In the following an example for the only Invoice

    @{
        var db = Database.Open("YourTable");
        var itot = db.QueryValue("SELECT SUM(Subtotal) AS Invoices FROM Salesord_hdr where Orderdate = 41190 and Invoicecount >= 1");
    }
    
    <!DOCTYPE html>
    
    <html lang="en">
        <head>
            <meta charset="utf-8" />
            <title></title>
            <style>
                .column1 {color: red; font-weight: bold;}
                .column2 {color: blue;}
            </style>
        </head>
        <body>
            <p>Invoices: 
                <span class=@(itot > 50 ? "column1" : "column2")>@itot.ToString("C")</span>
            </p>
        </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Webmatrix.data's Database entity to create a database connection, however it doesnt
I have developed a website using Razor (Microsoft WebMatrix) and now I want to
I am using MS webmatrix and razor. I have a query that uses the
I have three .cshtml created using WebMatrix: MyClass.cshtml located at App_Code: @functions { public
I'm learning razor syntax, using the startersite in WebMatrix and trying to display some
I'm learning ASP.Net web pages programming using Webmatrix (with razor syntax). Goal is to
I have a simple web service I wrote using Webmatrix that returns data in
This is my cshtml file in WebMatrix (Razor syntax). Is there some way to
How can I publish my website in Webmatrix that uses a database, using Web
I have developed a website using Asp.Net MVC which uses a SQL CE database

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.