ReadonlySelector

in namespace DotVVM.BusinessPack.Controls

Usage & Scenarios

Looks up a selected value in a collection and displays the matching item's text without offering an editor. Business Pack uses this control to display read-only cells in its combo box and drop-down list grid columns.

Sample 1: Displaying a name for a stored ID

SelectedValue contains a warehouse ID. ItemValueBinding identifies which property to match against that ID, while ItemTextBinding selects the name to show. Use the drop-down to change the ID and see the read-only label update.

With script chunks enabled (the default), the GridView script registers the selector's client binding. The sample requests that resource explicitly because it does not contain a grid. Omit dot:RequiredResource when using the full Business Pack bundle.

<dot:RequiredResource Name="dotvvm.businesspack.GridView" />
<bp:DropDownList DataSource="{value: Warehouses}" SelectedValue="{value: WarehouseId}"
                 ItemValueBinding="{value: Id}" ItemTextBinding="{value: Name}" />

<p>Ship from:</p>
<bp:ReadonlySelector DataSource="{value: Warehouses}" SelectedValue="{value: WarehouseId}"
                     ItemValueBinding="{value: Id}" ItemTextBinding="{value: Name}" />
using DotVVM.Framework.ViewModel;

namespace DotvvmWeb.Views.Docs.Controls.businesspack.ReadonlySelector.sample1
{
    public class ViewModel : DotvvmViewModelBase
    {
        public int WarehouseId { get; set; } = 1;
        public Warehouse[] Warehouses { get; set; } = new[]
        {
            new Warehouse { Id = 1, Name = "North depot" },
            new Warehouse { Id = 2, Name = "South depot" }
        };
    }

    public class Warehouse
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }
}

Sample 2: Matching a selected object

When SelectedValue contains the whole location rather than its code, use ItemKeyBinding instead of ItemValueBinding. The selector compares the locations by code and displays the name of the match. Change the drop-down selection to see the label update.

<dot:RequiredResource Name="dotvvm.businesspack.GridView" />
<bp:DropDownList DataSource="{value: Locations}" SelectedValue="{value: SelectedLocation}"
                 ItemKeyBinding="{value: Code}" ItemTextBinding="{value: Name}" />

<p>Selected location:</p>
<bp:ReadonlySelector DataSource="{value: Locations}" SelectedValue="{value: SelectedLocation}"
                     ItemKeyBinding="{value: Code}" ItemTextBinding="{value: Name}" />
using DotVVM.Framework.ViewModel;

namespace DotvvmWeb.Views.Docs.Controls.businesspack.ReadonlySelector.sample2
{
    public class ViewModel : DotvvmViewModelBase
    {
        public Location[] Locations { get; set; } = new[]
        {
            new Location { Code = "N", Name = "North depot" },
            new Location { Code = "S", Name = "South depot" }
        };

        public Location SelectedLocation { get; set; }

        public ViewModel()
        {
            SelectedLocation = Locations[0];
        }
    }

    public class Location
    {
        public string Code { get; set; }
        public string Name { get; set; }
    }
}

Properties

Name Type Description Notes Default Value
property icon DataSource IEnumerable Gets or sets the data source containing data for this control.
attribute
inner element
static value
bindable
default
null
property icon ItemKeyBinding IValueBinding Gets or sets the binding which retrieves the unique key of a data item.
attribute
inner element
static value
bindable
default
null
property icon ItemTextBinding IValueBinding<String> Gets or sets the binding which retrieves the text from a data item. It retrieves the whole item by default.
attribute
inner element
static value
bindable
default
null
property icon ItemValueBinding IValueBinding Gets or sets the binding which retrieves a value from a data item. It retrieves the whole item by default.
attribute
inner element
static value
bindable
default
null
property icon SelectedValue Object Gets or sets the selected value to be shown
attribute
inner element
static value
bindable
default
null

HTML produced by the control