|
<SfDropDownList @ref="ddl1" TValue="int?" Index="IndexVal" TItem="SpareNameViewModel" @bind-Value="@DDLValue" DataSource="@customData">
<DropDownListFieldSettings Text="Name" Value="Code"></DropDownListFieldSettings>
</SfDropDownList>
@code {
SfDropDownList<int?, SpareNameViewModel> genericCustomerPicker;
public IEnumerable<SpareNameViewModel> DataSource { get; set; }
public int? CustomCustDropValue
{
get; set;
}
SfDropDownList<int?, SpareNameViewModel> ddl1;
public ObservableCollection<SpareNameViewModel> customData { get; set; }
public int? DDLValue { get; set; }
public int? IndexVal { get; set; } = null;
protected override async Task OnInitializedAsync()
{
customData = await ForecastService.GetSpareNamesAsync();
this.StateHasChanged();
this.DDLValue = await ForecastService.GetSpareNamesValueAsync(); // Change Value
// add the datasource dynamically using addItems method
this.customData.Insert(0, new SpareNameViewModel() { Name = "Bob", Id = 10 });
}
}
|
|
|
|
<SfDropDownList Width="250px" DataSource=@DashBoards TValue=int? TItem=@DashBoard @bind-Value=@DashBoardId @ref=ddlDashBoards>
<DropDownListFieldSettings Value=@nameof(DashBoard.DashBoardId) Text=@nameof(DashBoard.Name) />
</SfDropDownList>
<SfButton OnClick=@Add>Add Fred</SfButton>
<SfButton OnClick=@Delete>Delete Mike</SfButton>
@code {
public class DashBoard : INotifyPropertyChanged
{
public DashBoard() { }
public string Name { get; set; }
public int DashBoardId
{
get { return _DashBoardId; }
set
{
_DashBoardId = value;
NotifyPropertyChanged("DashBoardId");
}
}
public int _DashBoardId { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
SfDropDownList<int?, DashBoard> ddlDashBoards;
protected int? DashBoardId { get; set; } = 1;
protected ObservableCollection<DashBoard> DashBoards { get; set; }
protected override async Task OnInitializedAsync()
{
this.DashBoards = new ObservableCollection<DashBoard>(new List<DashBoard>() {
new DashBoard { DashBoardId = 0, Name = "Bob" },
new DashBoard { DashBoardId = 1, Name = "Mike" },
new DashBoard { DashBoardId = 2, Name = "Glenn" },
new DashBoard { DashBoardId = 3, Name = "Guy" },
new DashBoard { DashBoardId = 4, Name = "Johnny" },
new DashBoard { DashBoardId = 5, Name = "Nick" } });
}
protected async Task Add()
{
this.DashBoards.Add(new DashBoard() { DashBoardId = 6, Name = "Fred" });
}
protected async Task Delete()
{
DashBoard DashBoardObj = this.DashBoards.Where(x => x.DashBoardId == 1).First<DashBoard>();
this.DashBoards.Remove(DashBoardObj);
}
public async Task<DashBoard> updateDate()
{
var data = new DashBoard() { DashBoardId = 6, Name = "Fred" };
return await Task.FromResult(data);
}
} |
|
protected override async Task OnInitializedAsync()
{
this.DashBoards = await GetItemsAsync();
}
public async Task<ObservableCollection<DashBoard>> GetItemsAsync()
{
return new ObservableCollection<DashBoard>() {
new DashBoard { DashBoardId = 0, Name = "Bob" },
new DashBoard { DashBoardId = 1, Name = "Mike" },
new DashBoard { DashBoardId = 2, Name = "Glenn" },
new DashBoard { DashBoardId = 3, Name = "Guy" },
new DashBoard { DashBoardId = 4, Name = "Johnny" },
new DashBoard { DashBoardId = 5, Name = "Nick" } };
} |
This is still an issue in Syncfusion.Blazor 19.1.0.63
Thank you for reply. You are correct: it works in your solution.
One difference between your solution and what I have is that my solution targets net5.0 standard.
The solution you've provided targets netstandard2.1
When I create a blank Blazor WASM solution targeting .net5.0 (not netstandard2.1), and try to implement the code, the control does not load Dashboards list. It returns "no records found"
Also, dropdown part of the control is not positioned correctly (its position is distorted)