How to get more than one Text in DropDownListFieldSettings
Hi, I'd like to be able to set "Text = @nameof(ApplicationUser.FirstName) + @nameof(ApplicationUser.LastName)", so that the DropDownList will display
"FirstName + LastName"
Question:
How do I concatenate the "Text" value in DropDownListFieldSettings so that it will display 'FirstName + LastName'?
Thank you.
SIGN IN To post a reply.
1 Reply
1 reply marked as answer
BC
Berly Christopher
Syncfusion Team
May 27, 2021 08:13 AM UTC
Hi Kenney,
Greetings from Syncfusion support.
We can achieve the requested requirement with help of value template support as mentioned in the below code example.
|
@using Syncfusion.Blazor.DropDowns;
<SfDropDownList TValue="string" TItem="GameFields" PopupHeight="230px" Placeholder="Select a game" DataSource="@Games">
<DropDownListFieldSettings Text="FirstName" Value="ID"></DropDownListFieldSettings>
<DropDownListTemplates TItem="GameFields">
<ValueTemplate>
<span class='name'>@((context as GameFields).FirstName) @((context as GameFields).LastName)</span>
</ValueTemplate>
</DropDownListTemplates>
</SfDropDownList>
@code {
public class GameFields
{
public string ID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}
private List<GameFields> Games = new List<GameFields>() {
new GameFields(){ ID= "Game1", LastName= "Olsen", FirstName="Hans" },
new GameFields(){ ID= "Game2", LastName= "Fuller", FirstName="Andrew" },
new GameFields(){ ID= "Game3", LastName= "Bond", FirstName="James" },
};
}
<style>
.name {
left: 9px;
position: absolute;
top: 4px;
}
</style> |
Screenshot:
Please refer the below UG and demo link to know more about template support.
Else, we can achieve the requested requirement by define the new variable and pass the value with desired format with help of get and set method. Kindly refer the below code example.
|
@using Syncfusion.Blazor.DropDowns;
<SfDropDownList TValue="string" TItem="GameFields" PopupHeight="230px" Placeholder="Select a game" DataSource="@Games">
<DropDownListFieldSettings Text="Name" Value="ID"></DropDownListFieldSettings>
</SfDropDownList>
@code {
public class GameFields
{
public string ID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string _Name;
public string Name
{
get
{
_Name = $"{FirstName} {LastName}";
return _Name;
}
set
{
_Name = value;
}
}
}
private List<GameFields> Games = new List<GameFields>() {
new GameFields(){ ID= "Game1", LastName= "Olsen", FirstName="Hans" },
new GameFields(){ ID= "Game2", LastName= "Fuller", FirstName="Andrew" },
new GameFields(){ ID= "Game3", LastName= "Bond", FirstName="James" },
};
} |
Screenshot:
Please find the sample from the below link.
Regards,
Berly B.C
Marked as answer
SIGN IN To post a reply.
- 1 Reply
- 2 Participants
- Marked answer
-
KP Kenney Phan
- May 26, 2021 10:08 PM UTC
- May 27, 2021 08:13 AM UTC