【问题标题】:Set checked attribute in Web Forms在 Web 窗体中设置选中的属性
【发布时间】:2014-11-28 21:36:55
【问题描述】:

我尝试为<input type="checkbox"/> 设置checked 属性:

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

但我得到一个错误

参数类型“字符串”不能分配给参数类型“布尔”

IsOperationPerformed 类型为 Boolean

如何添加cheched 属性?

【问题讨论】:

  • 您收到错误“IsOperationPerformed of type Boolean.”是什么意思?您收到的确切错误消息是什么。
  • 你可以尝试用单引号包裹属性,因为你可以看到这里的引号没有正确转义。
  • @BenRobinson,没有。我说 IsOperationPerformed 的类型为 bool,而我在这种转换中遇到错误
  • 好的,你遇到了什么错误?
  • 确保 IsOperationPerformed 不为 NULL。

标签: c# asp.net checkbox webforms checked


【解决方案1】:

据我所知,CheckBox should be equal to either true or false 没有选中或为空。如果问题仍然存在,请尝试更改并恢复。 希望我有所帮助。

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

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2015-11-22
  • 2023-03-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-23
  • 1970-01-01
相关资源
最近更新 更多