Search code examples
c#.netasp.net-mvc-3razorwebgrid

Checkbox in a column Grid


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?")
        )
})

Solution

  • 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' />")
    )