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 | |
|---|---|---|---|---|---|
| ClientIDMode | ClientIDMode | Gets or sets the client ID generation algorithm. |
attribute
static value
|
Static | |
| DataContext | Object | Gets or sets a data context for the control and its children. All value and command bindings are evaluated in context of this value. The DataContext is null in client-side templates. |
attribute
bindable
|
null | |
| DataSource | IEnumerable | Gets or sets the data source containing data for this control. |
attribute
bindable
|
null | |
| ID | String | Gets or sets the control client ID within its naming container. |
attribute
static value
bindable
|
null | |
| IncludeInPage | Boolean | Gets or sets whether the control is included in the DOM of the page. |
attribute
static value
bindable
|
True | |
| InnerText | String | Gets or sets the inner text of the HTML element. Note that this property can only be used on HtmlGenericControl directly and when the control does not have any children. |
attribute
static value
bindable
|
null | |
| ItemKeyBinding | IValueBinding | Gets or sets the binding which retrieves the unique key of a data item. |
attribute
bindable
|
null | |
| ItemTextBinding | IValueBinding<String> | Gets or sets the binding which retrieves the text from a data item. It retrieves the whole item by default. |
attribute
bindable
|
null | |
| ItemValueBinding | IValueBinding | Gets or sets the binding which retrieves a value from a data item. It retrieves the whole item by default. |
attribute
bindable
|
null | |
| SelectedValue | Object | Gets or sets the selected value to be shown |
attribute
static value
bindable
|
null | |
| Visible | Boolean | Gets or sets whether the control is visible. When set to false, `style="display: none"` will be added to this control. |
attribute
static value
bindable
|
True |