asp.net - Conditionally set Disabled and Checked attributes on HTML Elements -


i have button , checkbox in template field in asp gridview. want disabled property of button , checked property of checkbox set conditionally based on data field expiration. if expiration equals permanent, button should disabled , checkbox checked. if not, button enabled , 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 seems having disabled , checked attributes listed @ causing buttons disabled , checkboxes checked.

disabled , checked boolean attributes. accept only values disabled , checked respectively.

if don't want control checked/disabled default do not include attribute @ all.

since boolean attributes, may omit except value.

<input type="button"         id="expiration"         <%# (string)eval("expiration") == "permanant" ? "disabled" : "" %>         value='<%# eval("expiration") %>'> <input type="checkbox"         id="permanent"         <%# (string)eval("expiration") == "permanant" ? "checked" : "" %>> 

your checkbox should have explicit value though, see comment in dtd:

  value       cdata          #implied  -- specify radio buttons , checkboxes -- 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -