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

Bind a checkbox in an item template of a ListView to a datasource property

4 Answers 1439 Views
ListView
This is a migrated thread and some comments may be shown as answers.
rlapao
Top achievements
Rank 1
rlapao asked on 27 Apr 2012, 12:47 AM
Is it possible to bind a checkbox in an item template of a ListView to a datasource property without using a edit template.

For example:

<script type="text/x-kendo-tmpl" id="template">
     <div>
       <dl>
         <dt>Name</dt> <dd>${Name}</dd>
         <dt>Age</dt> <dd>${Age}</dd>
         <dt>Checked</dt> <dd><input type="checkbox" data-bind="checked:DataSourceBooleasProperty" /></dd>
       </dl>
     </div>
 </script>

$("#listView").kendoListView({
     dataSource: {
         data: createRandomData(50)
     },
     template: kendo.template($("#template").html())
 });

4 Answers, 1 is accepted

Sort by
0
Accepted
Alexander Valchev
Telerik team
answered on 02 May 2012, 08:23 AM
Hello Ricardo,

It is possible to display a boolean value through checked / unchecked check boxes through the template, but the inputs will not be bound (e.g. the changes will not affect the data records). 
<dt>Checked</dt><dd><input type="checkbox" #= BoolField ? checked="checked" : "" # /></dd>

If you want to edit the data, you have to define an edit template.
I hope this helps.

Kind regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
rlapao
Top achievements
Rank 1
answered on 02 May 2012, 09:12 AM
Hi Alexander,

Thanks for your reply.

Ricardo
0
Mark
Top achievements
Rank 2
answered on 28 Apr 2014, 09:48 PM
Can we similarly bind the image src and title?

I am trying as below:
<img id="HardWarning" #= IsHardWarning ? src="~/Images/jpgimage005.png":src="~/Images/jpgimage006.png" # style="width: 15px;height: 15px;" #= IsHardWarning? title="XXXX.": title="XXXXX."# />

But both properties are not populating properly.

<img id="HardWarning" ~="" images="" jpgimage006.png="" style="width: 15px;height: 15px;" this="" is="" soft="" warning.we="" can="" processed="" with="" this.="">

0
Alexander Valchev
Telerik team
answered on 29 Apr 2014, 06:52 AM
Hello Mark,

You should surround with quotes the whole string that will be returned.
<img id="HardWarning" #= IsHardWarning ? "src=\'~/Images/jpgimage005.png\'" : "src=\'~/Images/jpgimage006.png\'" # style="width: 15px;height: 15px;" #= IsHardWarning? "title=\'XXXX.\'" : "title=\'XXXXX.\'" # />


Regards,
Alexander Valchev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
ListView
Asked by
rlapao
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
rlapao
Top achievements
Rank 1
Mark
Top achievements
Rank 2
Share this question
or