Dear Support
Can you help me why the initial value from the Model ist not selected in the ComboBox?
public class TriggerCategory
{
[Key]
public int Id { get; set; }
[Required]
public string Title { get; set; }
public virtual ObservableCollection<Trigger> Triggers { get; set; }
}
@code {
IEnumerable<Trigger> Triggers { get; set; } = new List<Trigger>();
IEnumerable<TriggerCategory> TriggerCategories { get; set; } = new List<TriggerCategory>();
protected override async Task OnInitializedAsync()
{
var getResult = await TriggerRepository.GetAll();
if (getResult.IsSuccess)
{
Triggers = getResult.Result;
}
TriggerCategories = TriggerRepository.GetTriggerCategories();
}
async void Update(MouseEventArgs obj, Trigger trigger)
{
await TriggerRepository.Update(trigger);
}
}
div class="container">
<table class="table table-bordered">
<tr>
<th>ID</th>
<th>Title</th>
<th>Is Public</th>
<th>Owner</th>
<th>Category</th>
</tr>
@foreach (var trigger in Triggers)
{
<tr>
<td>@trigger.TriggerId.ToString()</td>
<td>
<SfTextBox @bind-Value="@trigger.TriggerTitle"></SfTextBox>
</td>
<td>
<SfCheckBox @bind-Checked="@trigger.IsPublic"></SfCheckBox>
</td>
<td>
@trigger.Owner.UserName
</td>
<td>
<SfComboBox Placeholder="Select Category"
@bind-Value="@trigger.TriggerCategory" DataSource="TriggerCategories"
AllowCustom="false"
AllowFiltering="false">
<ComboBoxFieldSettings Value="Id" Text="Title"></ComboBoxFieldSettings>
</SfComboBox>
</td>
<td>
<button class="btn btn-primary" @onclick="@(args => { Update(args, trigger); })">Update</button>
</td>
</tr>
}
</table>
</div>
Hi Patrick,
Based on your shared information, we suggest you use TValue and Titem property to bind the preselect value to the component.
Find the code changes here:
|
<table class="table table-bordered"> <tr> <th>ID</th> <th>Title</th> <th>Owner</th> <th>Category</th> </tr> @foreach (var trigger in TriggerCategories) { <tr> <td>@trigger.Id.ToString()</td> <td> <SfTextBox @bind-Value="@trigger.Name"></SfTextBox> </td> <td> @trigger.Name </td> <td> <SfComboBox Placeholder="Select Category" TValue="int?" TItem="SpareNameViewModel" @bind-Value="@trigger.Id" DataSource="TriggerCategories" AllowCustom="false" AllowFiltering="false"> <ComboBoxFieldSettings Value="Id" Text="Name"></ComboBoxFieldSettings> </SfComboBox> </td> </tr> } </table>
@code { public int? TriggerCategory { get; set; } ObservableCollection<SpareNameViewModel> TriggerCategories = new ObservableCollection<SpareNameViewModel>();
protected override async Task OnInitializedAsync() { TriggerCategories = await ForecastService.GetSpareNamesAsync(); }
} |
Find the sample in the attachment:
Regards,
Sureshkumar P