2012-11-03 130 views
0

我想創建一個價值內的WebGrid一個複選框的選擇,因爲INT內的WebGrid創建一個複選框

下面我怎麼做了......

grid.Column("",header:"Select",format:(item)=>Html.CheckBox(String.Format("{0}",(int)item.ID),false,new{id="chkSelected", Style="width:60px"})), 

,它正在爲我好,但我想使用類似下面

grid.Column(header: "{CheckBoxHeading}", format: 
      @<text><input class="box" type="checkbox" /></text>) 

注:我使用的aspx引擎上,而不是剃刀

好心幫me..how做我實現與發動機的aspx上述語法

感謝
阿曼

回答

0

下面是如何在MVC 3

使用的WebGrid列中的複選框一個簡單的演示我在我的模型中有一個名爲'HasPassport'的字段,它是布爾類型,我需要一個複選框列,以顯示每個真實值的選中複選框,否則顯示未選中的複選框。

使用下面的WebGrid.Column的格式參數是如何我都用過...

grid.Column(
header: "HasPassport ?", 
format: 
(col) => @Html.Raw(

"<input type='checkbox' checked='" + 

((col.HasPassport) ? "checked" : "") + 

"' disabled='true' />") 
) 

所以對於產生下面的HTML代碼爲「hasPassport」字段每一個真正的價值:

<input type='checkbox' checked='checked' disabled='true' /> 

PS摘自this文章。

0
grid.Column(
header: "HasPassport ?", 
format: 
(col) => @Html.Raw(

"<input type='checkbox' checked='" + 

((col.HasPassport) ? "checked" : "") + 

"' disabled='true' />") 
) 

這將始終不管檢查col.HasPassport

改性到

grid.Column("HasPassport?",header: "HasPassport", 
       format: (col) => @Html.Raw("<input type='checkbox' "+ ((col.HasPassport) ? "checked='checked'" : "") +"' disabled='true' />")),