Back to Devexpress

DxDropDownBox.GetDisplayText() Method

blazor-devexpress-dot-blazor-dot-dxdropdownbox-9648a55b.md

latest3.6 KB
Original Source

DxDropDownBox.GetDisplayText() Method

Returns a text defined by the QueryDisplayText function.

Namespace : DevExpress.Blazor

Assembly : DevExpress.Blazor.v25.2.dll

NuGet Package : DevExpress.Blazor

Declaration

csharp
public string GetDisplayText()

Returns

TypeDescription
String

The editor display text.

|

Remarks

The DxDropDownBox‘s input element is read-only for users. Use the Value property to assign an editor value programmatically and implement the QueryDisplayText function to define how the editor value is displayed in the input element.

Call the GetDisplayText method to get the text defined by the QueryDisplayText function.

The following code snippet uses EditBoxDisplayTemplate to customize edit box content. The QueryDisplayText function concatenates the last names of selected employees. The GetDisplayText method is called to get the function result and display it in the template.

razor
<DxDropDownBox @ref="ddbox" @bind-Value="Value" QueryDisplayText="QueryText" CssClass="ddBox">
    <EditBoxDisplayTemplate>
        <b>Selected employees: </b> @ddbox.GetDisplayText()
    </EditBoxDisplayTemplate>
    <DropDownBodyTemplate>
        <DxListBox Data="@ListBoxData" TData="Employee" TValue="Employee"
                    Values="@(GetListBoxValues(context.DropDownBox))"
                    ValuesChanged="@(values => ListBoxValuesChanged(values, context.DropDownBox))"
                    TextFieldName="@nameof(Employee.Text)"
                    SelectionMode="ListBoxSelectionMode.Multiple"
                    ShowCheckboxes="true"
                    CssClass="templateListbox" />
    </DropDownBodyTemplate>
</DxDropDownBox>

@code {
    DxDropDownBox ddbox;
    IEnumerable<Employee> ListBoxData { get; set; }
    object Value { get; set; }

    string QueryText(DropDownBoxQueryDisplayTextContext arg) {
        var names = (arg.Value as IEnumerable<Employee>)?.Select(x => x.LastName);
        return names != null ? string.Join(",", names) : string.Empty;
    }

    IEnumerable<Employee> GetListBoxValues(IDropDownBox dropDownBox) {
        return dropDownBox.Value as IEnumerable<Employee>;
    }

    void ListBoxValuesChanged(IEnumerable<Employee> values, IDropDownBox dropDownBox) {
        dropDownBox.BeginUpdate();
        dropDownBox.Value = values;
        dropDownBox.EndUpdate();
    }

    protected override async Task OnInitializedAsync() {
        ListBoxData = await NwindDataService.GetEmployeesAsync();
    }
}
css
.templateListbox {
    --dxbl-list-box-border-width: 0px;
    width: 100%
}
.ddBox {
    max-width: 480px;
    width: 100%;
}

Implements

GetDisplayText()

See Also

DxDropDownBox Class

DxDropDownBox Members

DevExpress.Blazor Namespace