This is a migrated thread and some comments may be shown as answers.

ClientTemplate checkbox databound to boolean

4 Answers 228 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Sebastian S
Top achievements
Rank 1
Sebastian S asked on 22 Jun 2010, 11:03 PM
Hi All,

I'm trying to bind a checkbox on the client side to a boolean value. I have the code below which works - except the checkbox value is bound to 'true' or 'false' string. Is there a standard way to bind booleans client side to a checkbox?

<%= Html.Telerik().Grid<MyStuff.Accounts>()
        .Name("Grid")
        .DataKeys(dataKeys => dataKeys.Add(c => c.AccountCode))
        .DataBinding(dataBinding => dataBinding.Ajax()
            .Select("_AjaxView", "Primary")
            )
        .Pageable(paging => paging.PageSize(12).Style(GridPagerStyles.NextPreviousAndInput))
        .Sortable()
        .Columns(columns =>
            {
                columns.Bound(c => c.LockedOut).ClientTemplate(@"<input type='checkbox' name='cbxLock' value='<#= LockedOut #>' readonly='readonly' />");

                columns.Bound(c => c.AccountCode).ReadOnly();
                columns.Bound(c => c.UserName);
            })
%>

Cheers,
--Sebastian

4 Answers, 1 is accepted

Sort by
0
Sebastian S
Top achievements
Rank 1
answered on 22 Jun 2010, 11:51 PM
Nevermind - fixed.Changed value to checked

ClientTemplate(@"<input type='checkbox' name='cbxLock' checked='<#= LockedOut#>' disabled />");


Hope this saves someone from a bit of anguish.

--Sebastian
0
Sebastian S
Top achievements
Rank 1
answered on 23 Jun 2010, 02:54 AM
Opps - should be this.

.ClientTemplate("<input type='checkbox' name='cbxLock' '<#= LockedOut?\"checked\":\"\" #>' disabled />");
0
Sean Cross
Top achievements
Rank 1
answered on 02 Feb 2011, 11:43 PM
Should be
.ClientTemplate("<input type='checkbox' name='cbxLock' <#= LockedOut?\"checked\":\"\" #> disabled />");

(no  around <#= LockedOut?\"checked\":\"\" #>)

or even
.ClientTemplate("<input type='checkbox' <#= LockedOut?\"checked\":\"\" #> disabled />");
0
Ethan
Top achievements
Rank 1
answered on 30 Mar 2011, 11:50 AM
the checkbox is disabled.. is there a way to make it enabled ? and to actually bound it to the field in the model..
so when i check a record's checkbox it will save 'true' on the appropriate model field (which is bound to the checkbox)..

Tags
Grid
Asked by
Sebastian S
Top achievements
Rank 1
Answers by
Sebastian S
Top achievements
Rank 1
Sean Cross
Top achievements
Rank 1
Ethan
Top achievements
Rank 1
Share this question
or