ListBox and checkboxes
The ListBox control has a checkedMemberPath property that allows you to add checkboxes to items on the list. It has a checkedItems property that gets or sets the list of checked items.
Checked Items:
- C1Input/ListBoxCheckBoxes.js
- C1Input/ListBoxCheckBoxes.css
- ListBoxCheckBoxesController.cs
- ListBoxCheckBoxes.cshtml
1 2 3 4 5 6 7 8 9 10 11 12 13 | // This file locates: "Scripts/Lesson/C1Input/ListBoxCheckBoxes.js". c1.documentReady(function () { var theListBox = wijmo.Control.getControl( '#theListBox' ); theListBox.checkedMemberPath = "selected" ; theListBox.checkedItemsChanged.addHandler(function (s, e) { var arr = s.checkedItems, html = '' ; for (var i = 0; i < arr.length; i++) { html += wijmo.format( '<li>{Country}</li>' , arr[i]); } document.getElementById( 'checkedItems' ).innerHTML = html; }); }); |
1 2 3 4 | // This file locates: "Content/css/Lesson/C1Input/ListBoxCheckBoxes.css". #theListBox label{ text-align:left; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 | using System.Web.Mvc; namespace LearnMvcClient.Controllers { public partial class C1InputController : Controller { // GET: ListBoxCheckBoxes public ActionResult ListBoxCheckBoxes() { return View(Models.Gdp.GetData()); } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | @model IEnumerable< Gdp > < h1 > @Html .Raw(Resources.C1Input.ListBoxCheckBoxes_Title) </ h1 > < p > @Html .Raw(Resources.C1Input.ListBoxCheckBoxes_Text1) </ p > < div class = "row demo-settings" > < div class = "col-xs-5" > @ (Html.C1().ListBox< Gdp >().Id( "theListBox" ) .Height(200) .Bind(Model).DisplayMemberPath( "Country" ) ) </ div > < div class = "col-xs-7" > < p > @Html .Raw(Resources.C1Input.ListBoxCheckBoxes_Text2) </ p > < ul id = "checkedItems" ></ ul > </ div > </ div > |