ComboBox
Item Template
This sample shows how to use ItemTemplateId to specify custom content in ComboBox.
Features
Description
This sample shows how to use ItemTemplateId to specify custom content in ComboBox.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; namespace MvcExplorer.Controllers { public partial class ComboBoxController : Controller { public ActionResult ItemTemplate() { var list = GetSystemColors(); return View(list); } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | @model IEnumerable< NamedColor > @section Styles{ < style > .palette { display: inline-block; border: 1px solid black; width: 20px; height: 10px; } .palette-label { margin-left: 5px; } </ style > } <script id="template1" type="text/template"> < span > < span class = "palette" style = "background-color: {{Value}}" ></ span > < span class = "palette-label" >{{Name}}</ span > </ span > </script> < div > < label > @Html .Raw(Resources.ComboBox.ItemTemplate_Colors)</ label > @ (Html.C1().ComboBox() .Bind(Model) .DisplayMemberPath( "Name" ) .SelectedValuePath( "Value" ) .ItemTemplateId( "template1" ) .Width(250) ) </ div > @section Description{ < p > @Html .Raw(Resources.ComboBox.ItemTemplate_Text0)</ p > } |