Search code examples
asp.net-mvc-4webgrid

Displaying a boolean as a Yes/No within a Webgrid


I am trying to use a Webgrid and I can get the data to display but the bool values are where I'm having problems. I would like to just display Yes or No instead of true or false.

 webGridColumns.Add(new WebGridColumn 
{ ColumnName = "IsActive", CanSort = true, Header = "Is Active" });

Whats the right way to do this. Please give some idea


Solution

  • I found the answer myself after doing some search.

    If anybody faces this problem, I hope it will help them.

    webGridColumns.Add(new WebGridColumn { 
        ColumnName = "IsActive",
        Header = "Is Active",
        CanSort = true,
        Format= @<text>
            @(item.IsActive ? "Yes" : "No" )
        </text>}
    );