0

I try to set checked attribute for <input type="checkbox"/>:

checked="<%#Convert.ToBoolean(DataBinder.Eval(Container.DataItem, "IsOperationPerformed")) ? "checked" : string.Empty%>"

But I get an error

Argument type ‘string’ is not assignable to parameter type ‘bool’

IsOperationPerformed of type Boolean.

How can I add cheched attribute?

demo
  • 6,038
  • 19
  • 75
  • 149

1 Answers1

0

As per my knowledge, CheckBox should be equal to either true or false and not checked or empty. Try changing it and revert if problem still occurs. Hope i helped.

checked="<%#Convert.ToBoolean(DataBinder.Eval(Container.DataItem, "IsOperationPerformed")) ? TRUE : FALSE%>"
Arindam Nayak
  • 7,346
  • 4
  • 32
  • 48
ALOK
  • 553
  • 6
  • 17
  • this helps, thanks. However i always think that chechbox can be checked or cheched="checked" – demo Nov 28 '14 at 13:25
  • But as OP has said , it was showing some error, it has to do with some code. But `checked=checked` also works.- http://www.w3schools.com/tags/att_input_checked.asp - http://stackoverflow.com/questions/7851868/whats-the-proper-value-for-a-checked-attribute-of-an-html-checkbox – Arindam Nayak Nov 28 '14 at 13:27
  • @Alok, you havn't solved OP's original problem , and checked with any value will always work - http://stackoverflow.com/questions/7851868/whats-the-proper-value-for-a-checked-attribute-of-an-html-checkbox – Arindam Nayak Nov 28 '14 at 13:29
  • @ArindamNayak thats html and i dont know it works with asp.net or not but correct way is it should be true or false. http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.checkbox.checked(v=vs.110).aspx – ALOK Nov 28 '14 at 13:32
  • 1
    I will surely try and find out whether checked="checked" works or not but the code was wrong as string.empty will return empty to check...And yes only checked works to set default to check. – ALOK Nov 28 '14 at 13:34