|
<SfDropDownList @ref="DDLObject" TItem="GameFields" TValue="string" PopupHeight="230px" Placeholder="Select a game" @bind-Value="@DropVal" DataSource="@Games">
<DropDownListFieldSettings Text="Text" Value="ID"></DropDownListFieldSettings>
</SfDropDownList>
<button @onclick="@AddDataSource">Click to add the datasource</button>
@code
{
SfDropDownList<string, GameFields> DDLObject;
public class GameFields
{
public string ID { get; set; }
public string Text { get; set; }
}
private ObservableCollection<GameFields> Games = new ObservableCollection<GameFields>() {
new GameFields(){ ID= "Game1", Text= "American Football" },
new GameFields(){ ID= "Game2", Text= "Badminton" },
new GameFields(){ ID= "Game3", Text= "Basketball" },
new GameFields(){ ID= "Game4", Text= "Cricket" },
new GameFields(){ ID= "Game5", Text= "Football" },
new GameFields(){ ID= "Game6", Text= "Golf" },
new GameFields(){ ID= "Game7", Text= "Hockey" },
new GameFields(){ ID= "Game8", Text= "Rugby"},
new GameFields(){ ID= "Game9", Text= "Snooker" }
};
public string DropVal;
public void AddDataSource()
{
// add the datasource dynamically using addItems method
this.Games.Insert(0,new GameFields() { ID = "Game10", Text = "Tennis" });
this.DropVal = "Game10";
}
} |