New to Telerik UI for Blazor? Download free 30-day trial

DropDownList Templates

The DropDownList component allows you to change what is rendered in its items, body, header and footer through templates.

In this article:

Value Template

The ValueTemplate determines how the selected item renders in the main element of the dropdown list that is always visible. By default, the text from the model is rendered.

The ValueTemplate exposes a context which represents the selected item object. Use it to render the selected item details.

Item Template

The ItemTemplate determines how the individual items are rendered in the dropdown of the component. By default, the text from the particular suggestions is rendered.

The ItemTemplate exposes a context which represents the data item object. Cast it to the respective model type to access or render the item properties.

Header Template

The HeaderTemplate controls the content that you can place above the list of items inside the dropdown element. It is always visible when the combobox is expanded. By default it is empty.

The FooterTemplate allows you to render content below the list of items inside the dropdownlist element. It is always visible when the dropdown is expanded. By default it is empty.

No Data Template

The NoDataTemplate controls the content of the popup element when the component does not have any items. By default, simply "No data" text is rendered.

Example

Using AutoComplete Templates

@* DropDownList component with ValueTemplate, HeaderTemplate, ItemTemplate, FooterTemplate and NoDataTemplate *@

<p>
    <TelerikCheckBox @bind-Value="@IsDataAvailable" OnChange="@OnCheckBoxChangeHandler" />
    DropDownList has data
</p>

<TelerikDropDownList Data="@DropDownData" @bind-Value="@Role">
    <ValueTemplate>
        <strong>Selected role:</strong> @context
    </ValueTemplate>
    <HeaderTemplate>
        <strong>Select one of the following:</strong>
    </HeaderTemplate>
    <ItemTemplate>
        Are you a <strong>@context</strong>
    </ItemTemplate>
    <FooterTemplate>
        <h6>Total Positions: @DropDownData.Count()</h6>
    </FooterTemplate>
    <NoDataTemplate>
        <div class="no-data-template">
            <TelerikSvgIcon Size="@ThemeConstants.SvgIcon.Size.Large" Icon="@SvgIcon.FilesError"></TelerikSvgIcon>
            <p>No items available</p>
        </div>
    </NoDataTemplate>
</TelerikDropDownList>

@code {
    private string Role { get; set; }

    private bool IsDataAvailable { get; set; } = true;

    private List<string> DropDownData { get; set; }

    private List<string> SourceData { get; set; } = new List<string> { "Manager", "Developer", "QA", "Technical Writer", "Support Engineer", "Sales Agent", "Architect", "Designer" };

    protected override void OnInitialized()
    {
        DropDownData = SourceData;
    }

    private void OnCheckBoxChangeHandler()
    {
        if (IsDataAvailable)
        {
            DropDownData = new List<string>(SourceData);
        }else{
            DropDownData = new List<string>();
        }
    }
}

See Also

In this article