I have some short questions about the Webgrid.
-
How can I put in a column the current number ? (I’m using EF)
-
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)))
You could use a view model and instead of binding your WebGrid to the
Model, bind it to aModel.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.You could use a custom
formatfor the column.Here’s an example:
as you can see we have used the
Html.FormatHeightcustom extension method which could look like this: