Display a boolean as a checkbox in Webgrid

I am trying to use Webgrid and I can get the data to display, but the bool values ​​are where I am having problems. I would just like to show a checkbox that matters to my bool. I managed to check the box in the grid, but it is editable and does not display the value correctly.

grid.GetHtml(tableStyle: "table", alternatingRowStyle: "alternate", headerStyle: "header",
columns: grid.Columns(grid.Column(columnName: "string1", header: "String1", format: @<text>@item.string1</text>),
grid.Column(columnName: "bool1", header: "bool1", format: bool1? </text>),

If someone has done this before and could shed some light on how to correctly display bool as a flag to be evaluated!

+5
source share
2 answers

Try this for the bool column:

grid.Column(columnName: "bool1", 
    header: "bool1", 
    format: (item) => @Html.Raw("<input type='checkbox' " + ((item.bool1==true) ? "checked" : "") + " disabled='disabled' />")
)
+14
source

Below is the working code for the checkbox in mvc5.

grid.column("Active", header: "Assign",
  @if (@item.Active){<input type="checkbox" checked="checked"  spellcheck="true"/>}
  else{<input type="checkbox"  spellcheck="true" />} </text>) 
0
source

All Articles