I am using a number of comboboxes in my blazor server project it is always showing data. Sometimes they are empty, other times they display data.
My app fetches data via a service is then used as datasource to the comboboxes. I have included relevant code blocks from my app below
//code snippet for comboboxes
<div class="col-6 form-group">
<SfComboBox TValue="string"
TItem="TaxCodeLookup"
@bind-Value="@TaxCodeId"
DataSource="@GetTaxCodes"
AllowFiltering="true"
PopupHeight="100"
Placeholder="Select Tax Code"
FloatLabelType="FloatLabelType.Always">
<ComboBoxFieldSettings Text="CodeRate" Value="Id">
</ComboBoxFieldSettings>
</SfComboBox>
</div>
<div class="col-6 form-group">
<SfComboBox TValue="string"
DataSource="@GetCategoryLookups()"
TItem="CategoryLookup"
@bind-Value="@CategoryId"
AllowFiltering="true"
Placeholder="Select Category"
FloatLabelType="FloatLabelType.Always">
<ComboBoxFieldSettings Text="Name" Value="Id">
</ComboBoxFieldSettings>
</SfComboBox>
</div>
<div class=" col-6 form-group">
<SfComboBox TItem="SupplierLookup"
TValue="string"
DataSource="@GetSuppliers"
Placeholder="Sales Nominal Code"
FloatLabelType="FloatLabelType.Always">
<ComboBoxFieldSettings Text="" Value="">
</ComboBoxFieldSettings>
</SfComboBox>
</div>
<div class="col-6 form-group">
<SfComboBox TValue="string"
TItem="DepartmentLookup"
@bind-Value="@DepartmentId"
DataSource="@GetDepartments"
AllowFiltering="true"
Placeholder="Department"
FloatLabelType="FloatLabelType.Always">
<ComboBoxFieldSettings Text="Name" Value="Id">
</ComboBoxFieldSettings>
</SfComboBox>
</div>
//Componentbase code
[Inject]
public IProductService ProductService { get; set; }
[Inject]
public ICategoryService CategoryService { get; set; }
[Inject]
public ITaxCodeService TaxCodeService { get; set; }
[Inject]
public ISupplierService SupplierService { get; set; }
[Inject]
public IDepartmentService DepartmentService { get; set; }
public List<CategoryLookup> GetCategories { get; set; } = new List<CategoryLookup>();
public List<TaxCodeLookup> GetTaxCodes { get; set; } = new List<TaxCodeLookup>();
public List<DepartmentLookup> GetDepartments { get; set; } = new List<DepartmentLookup>();
public List<SupplierLookup> GetSuppliers { get; set; } = new List<SupplierLookup>();
protected ProductForRegisterDto product { get; set; } = new ProductForRegisterDto();
[Inject]
public NavigationManager navigationManager { get; set; }
//[Parameter]
//public string Id { get; set; } = "";
protected string SupplierId { get; set; } = "";
protected string TaxCodeId { get; set; } = "";
protected string CategoryId { get; set; } = "";
protected string DepartmentId { get; set; } = "";
public string GetProductCode { get; set; } = "";
protected override void OnInitialized()
{
base.OnInitialized();
{ }
}
protected async override Task OnInitializedAsync()
{
GetTaxCodes = (await TaxCodeService.GetTaxCodeLookups()).ToList();
GetCategories = (await CategoryService.GetCategoryLookup()).ToList();
GetSuppliers = (await SupplierService.GetSupplierLookup()).ToList();
GetDepartments = (await DepartmentService.GetDepartmentLookup()).ToList();
}