【问题标题】:Dynamically added checked attributes C#动态添加选中的属性 C#
【发布时间】:2013-01-08 09:41:56
【问题描述】:

我是 C# ASP .Net 的新手。我有这样的问题:
我有这样的数据库数据:

button_id | button_access
-------------------------
btnSearch | true
btnClear  | true
btnAdd    | false
btnSave   | false

在我看来:

@data [data from database]
...
@foreach (chk in data) {
  <input name="btnSearch" type="checkbox" value="@chk.button_id" {???} />
}
...

我认为,在{???} 中,我必须插入如下条件:

IF (chk.buttonAccess) {
   //Code to write attribute checked
}

{???}..我该填什么?

【问题讨论】:

    标签: c# asp.net asp.net-mvc checkbox


    【解决方案1】:

    试试这个:

    @(chk.button_access ? "checked" : "")
    

    【讨论】:

      猜你喜欢
      • 2015-12-12
      • 1970-01-01
      • 2011-12-15
      • 1970-01-01
      • 1970-01-01
      • 2010-09-12
      • 1970-01-01
      • 2013-03-27
      • 1970-01-01
      相关资源
      最近更新 更多