DotVVM Tip 07: Use ComboBox to select values from a collection

Published: 11/28/2022 1:18:00 PM

DotVVM Tips is a series of short articles showing interesting features of DotVVM. To learn more, visit our Docs site.

Building forms is really easy! Bind a collection of objects in the ComboBox control and let the user select the value.

// DotVVM view
<dot:ComboBox DataSource="{value: Customers}"
              ItemTextBinding="{value: FullName}"
              ItemValueBinding="{value: Id}"
              SelectedValue="{value: SelectedCustomerId}" />
// DotVVM viewmodel
public List<Customer> Customers { get; set; } = new();
public int SelectedCustomerId { get; set; }

The ItemTextBinding tells the control what property should serve as the display text on the list items. The ItemValueBinding tells that the Id property of the selected object will be stored to the property set as the SelectedValue.

Tomáš Herceg

I am the CEO of RIGANTI, a small software development company located in Prague, Czech Republic.

I am Microsoft Most Valuable Professional and the founder of DotVVM project.