6

I am trying to use a Webgrid and I can get the data to display but the bool values are where I'm having problems. I would like to just display a checkbox that has the value of my bool. I have been able to get a checkbox within the grid but it is editable and does not show 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 properly display a bool as a checkbox that would be appreciated!

4

2 に答える 2

15

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' />")
)
于 2012-05-17T16:36:36.687 に答える
0

Below is working code for 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>) 
于 2014-12-19T21:44:41.467 に答える