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

DropDownList TextField concatenate

1 Answer 535 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Vishnu
Top achievements
Rank 1
Iron
Veteran
Vishnu asked on 25 Oct 2020, 10:16 AM

 

Hi, I am not able to concatenate value in TextField for selected value eg: (Code+ '-' +Name) 

<TelerikDropDownList DefaultText="NONE" Data="@categotyTypes" @bind-Value="@Model.Code"
                                     TextField="@nameof(CategoryTypes.Name)"
                                     ValueField="@nameof(CategoryTypes.Code)" Id="CategoryCode" Width="100%">
                    <ItemTemplate Context="dlContext">
                        @($"{dlContext.Code} - {dlContext.Name}")
                    </ItemTemplate>
                </TelerikDropDownList>

Could you please help on this.

1 Answer, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 25 Oct 2020, 04:34 PM

Hi Vishnu,

Here's an example based on the documentation: https://docs.telerik.com/blazor-ui/components/dropdownlist/templates#item-template

<TelerikDropDownList Data="@myDdlData" TextField="MyTextField" ValueField="MyValueField" Value="1">
    <ItemTemplate>
        @{
            MyDdlModel currItem = context as MyDdlModel;
            string textToRender = $"{currItem.MyTextField} - {currItem.ExtraField}";
            @textToRender
        }
    </ItemTemplate>
</TelerikDropDownList>


@code {
    public class MyDdlModel
    {
        public int MyValueField { get; set; }
        public string MyTextField { get; set; }
        public string ExtraField { get; set; }
    }

    IEnumerable<MyDdlModel> myDdlData = Enumerable.Range(1, 20).Select(x =>
            new MyDdlModel
            {
                MyTextField = "item " + x,
                MyValueField = x,
                ExtraField = "more item info " + x
            }
        );
}

 

Regards,
Marin Bratanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
General Discussions
Asked by
Vishnu
Top achievements
Rank 1
Iron
Veteran
Answers by
Marin Bratanov
Telerik team
Share this question
or