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

Autor:
|
Publikováno:

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
Tomáš Herceg

BIO: 

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

I am a Microsoft Regional Director and Microsoft Most Valuable Professional.

I am the author of DotVVM, an open source .NET-based web framework which lets you build Line-of-Business applications easily and without writing thousands lines of Javascript code.

Ostatní články z kategorie: DotVVM Blog