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 7958083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:21:56+00:00 2026-06-04T04:21:56+00:00

I have some short questions about the Webgrid. How can I put in a

  • 0

I have some short questions about the Webgrid.

  1. How can I put in a column the current number ? (I’m using EF)

  2. How can I display a string instead of a integer ?
    (Let’s say I have a int field height and if it’s between 1.50- 1.60 I would like to see in the webgrid small , 1.60-1.70 – normal , 1.7-1.8 – big, >2 – huge )

Crt. No. | height old | height new

1 | 1.55 | small

2 | 1.78 | normal

3 | 2.40 | huge

@grid.GetHtml(tableStyle: "table",
          alternatingRowStyle: "alternate",
          headerStyle: "header",
          columns: grid.Columns(
          grid.Column(columnName: "?",header: "Crt. No.", canSort: true),
          grid.Column(columnName: "height", header: "height old", canSort: true),
          grid.Column(columnName: "height?", header: "height new", canSort: true)))
  • 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-04T04:21:57+00:00Added an answer on June 4, 2026 at 4:21 am

    1). How can I put in a column the current number ? (I’m using EF)

    You could use a view model and instead of binding your WebGrid to the Model, bind it to a Model.Select((item, index) => new { Index = index, Element = item }) or even better use a real view model that possess those 2 properties instead of using an anonymous object.

    2). How can I display a string instead of a integer ? (Let’s say I
    have a int field height and if it’s between 1.50- 1.60 I would like to
    see in the webgrid small , 1.60-1.70 – normal , 1.7-1.8 – big, >2 –
    huge )

    You could use a custom format for the column.

    Here’s an example:

    @model IEnumerable<SomeModel>
    
    @{
        var grid = new WebGrid(Model.Select((item, index) => new { Index = index, Element = item }));
    }
    
    @grid.GetHtml(
        tableStyle: "table",
        alternatingRowStyle: "alternate",
        headerStyle: "header",
        columns: grid.Columns(
            grid.Column(columnName: "Index", header: "Crt. No.", canSort: true),
            grid.Column(
                header: "height old", 
                canSort: true, 
                format: 
                    @<text>
                        @item.Element.height
                    </text>
            ),
            grid.Column(
                header: "height new", 
                canSort: true, 
                format: 
                    @<text>
                        @Html.FormatHeight((double)item.Element.height)
                    </text>
            )
        )
    )
    

    as you can see we have used the Html.FormatHeight custom extension method which could look like this:

    public static class HtmlExtensions
    {
        public static IHtmlString FormatHeight(this HtmlHelper htmlHelper, double height)
        {
            if (height < 1.5)
            {
                return new HtmlString("tiny");
            }
            if (height > 1.5 && height < 1.6)
            {
                return new HtmlString("small");
            }
            else if (height > 1.6 && height < 1.7)
            {
                return new HtmlString("normal");
            }
            else if (height > 1.7 && height < 1.8)
            {
                return new HtmlString("big");
            }
    
            return new HtmlString("huge");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know there have been some questions about this, but I can't seem to
I have some questions about the following code: using System; namespace ConsoleApplication2 { public
I have some fundamental points/questions about OpenGL, not all involving code but concepts as
Short version of my questions: Can anyone point me toward some good, detailed sources
I have some questions about multi-threaded programming and multi-core usage. In particular I'm wondering
I have already asked some questions about this topic, I have made some modifications
I have some questions about the concept of static polymporhism I somethimes hear about;
I have some basic PHP code: $raceramps56[short] = My Test Product; $leftMenu = '<div
Let's say we have a box with some short paragraphs: <div style=overflow:hidden> <p>Some text</p>
So long story short, i have some forms (2) of them that, need different

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.