I have a button and a checkbox in a template field in an asp GridView. I want the disabled property of the button and the checked property of the checkbox to be set conditionally based on the Data Field Expiration. If Expiration equals Permanent, then the button should be disabled and the checkbox checked. If not, then the button is enabled and checkbox unchecked. I’ve tried:
<input type="button" id="expiration" disabled='<%# (string)Eval("Expiration") == "Permanant" ? "disabled" : "enabled" %>' value='<%# Eval("Expiration") %>'/>
<input type="checkbox" id="permanent" checked= '<%# (string)Eval("Expiration") == "Permanant" ? "checked" : "unchecked" %>'/>
But it seems that just having the disabled and checked attributes listed at all is causing all buttons to be disabled and all checkboxes checked.
disabledandcheckedare boolean attributes. They accept only the valuesdisabledandcheckedrespectively.If you don’t want the control to be checked/disabled by default then do not include the attribute at all.
Since they are boolean attributes, you may omit everything except the value.
Your checkbox should have an explicit value though, see the comment in the DTD: