Reputation: 337
I have a Grid in Asp.net MVC 3, I want that in the column "Active?" displays a checkbox indicating if the user is active or not, now I get the word "true".
I want to change the word "true" for a check box that can not be changed, how i do this?
@grid.GetHtml( fillEmptyRows: false,
tableStyle : "table",
mode: WebGridPagerModes.All,
columns: new [] {
grid.Column("IdUser", header: "User"),
grid.Column("Name", header: "Name"),
grid.Column("Lastname", header: "Lastname"),
grid.Column( "Active" ,header: "Active?")
)
})
Upvotes: 2
Views: 2587
Reputation: 11
You can use this:
grid.Column(
"Active",
format: item => @Html.CheckBox("Active", (bool)(item.Active ?? false), new { @disabled = "disabled" }), style: "center"
)
The 'style: "center"' may be omitted if you want :)
Good luck!
Upvotes: 1
Reputation: 102793
You can use WebGrid.Column's format parameter for this.
grid.Column(
header: "Active",
format: (col) => @Html.Raw("<input type='checkbox' checked='" + ((col.Active) ? "checked" : "") + "' disabled='true' />")
)
Upvotes: 3