This is a migrated thread and some comments may be shown as answers.

DropDownList TextField from combined properties

2 Answers 1327 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Artem
Top achievements
Rank 1
Veteran
Artem asked on 21 Aug 2020, 08:14 PM

Hi,

I have a dropdownlist and I want to have a TextField as a combined value between two properties of the context

I can do this using <ItemTemplate> and it works, but only when I click on dropdown and see the list, list has items with combined properties

When I select one item from that list and list is closed, the selected text in drop down list is not combined, it shows only code in my case

How can I show selected value as Item Template? Code ( Description )

<TelerikDropDownList Data="@Sites"
                     ValueChanged="@( (int v) => SiteValueChangedHandler(v) )"
                     TextField="@nameof(Site.Code)"
                     ValueField="@nameof(Site.SiteId)"
                     DefaultText="@LanguageContainer.Keys["All"]"
                     Width="200px"
                     Id="ddlSite">
    <ItemTemplate>
        @(string.Concat((context as Site).Code, " (", (context as Site).Description, ")"))
    </ItemTemplate>
</TelerikDropDownList>

 

Thanks,

Artem


2 Answers, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 22 Aug 2020, 07:37 AM

Hello Artem,

The ValueTemplate lets you determine how the selected item renders: https://docs.telerik.com/blazor-ui/components/dropdownlist/templates#value-template.

 

Regards,
Marin Bratanov
Progress Telerik

Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive , special prizes and more, for FREE?! Register now for DevReach 2.0(20).

0
Artem
Top achievements
Rank 1
Veteran
answered on 24 Aug 2020, 04:00 PM

Hi Marin,

I tried your example and it works.

 

Thanks,

Artem

Tags
DropDownList
Asked by
Artem
Top achievements
Rank 1
Veteran
Answers by
Marin Bratanov
Telerik team
Artem
Top achievements
Rank 1
Veteran
Share this question
or