0

i want to create a checkbox option inside webgrid with value as int

below how i have done...

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

it is working fine for me, but i wanted to use something like below

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

note: i am using aspx engine instead on razor

kindly help me..how do i achieve the above syntax with aspx engine

thanks
Aman

aamankhaan
  • 491
  • 1
  • 9
  • 35

2 Answers2

0

Below is a simple demonstration on how to use checkbox inside a webgrid column in MVC 3.

I had a field called ‘HasPassport‘ in my model which was of type boolean for which I required a checkbox column, to show a checked checkbox for every true value and an unchecked checkbox otherwise.

Using the WebGrid.Column’s format parameter below is how I have used…

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

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

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

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

So for every true value for the ‘hasPassport’ field the following HTML code is generated :

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

P.S Taken from this article.

Yasser Shaikh
  • 46,934
  • 46
  • 204
  • 281
0
grid.Column(
header: "HasPassport ?",
format:
 (col) => @Html.Raw(

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

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

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

this will always be checked irrespective of col.HasPassport value

Modified to

grid.Column("HasPassport?",header: "HasPassport", 
                format:  (col) => @Html.Raw("<input type='checkbox' "+ ((col.HasPassport) ? "checked='checked'" : "") +"' disabled='true' />") ),
Alvaro Menéndez
  • 8,766
  • 3
  • 37
  • 57