Wednesday, February 27, 2013

Telerik ASP.Net MVC Grid–Ajax binding boolean property

When you bind a collection of objects that have a boolean property on them and if you use server side binding, the columns are automatically rendered as check-boxes. But instead, if you use AJAX binding with the telerik MVC grid, they get rendered as literal texts (“true” or “false”). To fix it, what you need to do is to set the ClientTemplate. Here is an example:

grid.Columns(columns => {
columns.Bound(o => o.Value).ClientTemplate("<input type='checkbox' <#=Value?'checked':''#> disabled />");

Where the code that’s highlighted is the binding code and “Value” is the property to which I am binding. Also, I am using the ternary operator to output “checked:’’” if its true, else it outputs nothing.

  

No comments:

Post a Comment

Remember, if you want me to respond to your comment, then you need to use a Google/OpenID account to leave the comment.