Adding Checkbox to gridview

Mar 27, 2014 at 9:23 PM
I used entity framework to build my model and I have my data displaying in a grid view now. However, I have several fields that have a value of Y or N and I want to display this data as checkboxes. I have used the RenderValueAs to create the checkboxes, but nothing I do will set the checkbox values correctly. I just want to do something like: if model.value = 'Y' then checked, else unchecked.

How can I accomplish this?
Coordinator
Apr 5, 2014 at 7:24 AM
Hi,
you can setup 'checked' attribute of input element, besed on your condition:
<input type="checkbox" checked="@model.X == 5" />
Please see for more infomation about conditional attributes: http://stackoverflow.com/questions/9399531/asp-net-mvc-razor-conditional-attribute-in-html