Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying a boolean as a checkbox within a Webgrid

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!

like image 668
RicketyBowby Avatar asked May 17 '12 16:05

RicketyBowby


1 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' />")
)
like image 53
McGarnagle Avatar answered Sep 28 '22 08:09

McGarnagle