We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Get Id of Selected Object

I'm trying to use Combobox to select an item.

Here's my code:

 <EjsComboBox    TValue="SFObject" @ref="Combo" Placeholder="Auswählen" OnChange="LookUp"  @bind-Value="@SelectedSFItem" DataSource="@SFList"  IgnoreAccent=true  FilterType="Syncfusion.EJ2.Blazor.DropDowns.FilterType.Contains">
        <ComboBoxFieldSettings    Value="Name"> </ComboBoxFieldSettings>

SFList ist a List<SFObject> and SFObject Contains several properties. I want to Display the Name property in the Combobox, but I Need my Id Property to consume the selection.

How can I achieve this. It seems there is no DisplayMember/ ValueMember and i can't find the SelectedItem anywhere in my @ref=Combo Object.

The SelectedSFItem also stays empty...

Any suggestions?

Thanks Michael

1 Reply

NP Narayanasamy Panneer Selvam Syncfusion Team November 11, 2019 09:55 AM UTC

Hi Michael,

Greetings from Syncfusion support.

We have validated your requirement. Yes, you can get the selected object’s ID through ItemData by using OnValueSelect event argument. Here you can get ID field by deserializing the ItemsData. Please refer the below code example,
Code example:  
@using Syncfusion.EJ2.Blazor.DropDowns; 
@using Newtonsoft.Json;   
        <EjsComboBox TValue="string" @ref="comboObj" PopupHeight="230px" Index=2 Placeholder="Select a game" DataSource="@Games"> 
            <ComboBoxEvents TValue="string" OnValueSelect="@OnValSelect"> </ComboBoxEvents> 
            <ComboBoxFieldSettings Value="Text"></ComboBoxFieldSettings> 
  public void OnValSelect(Syncfusion.EJ2.Blazor.DropDowns.SelectEventArgs args) 
        string output = JsonConvert.SerializeObject(args.ItemData); 
       var SelectedID = JsonConvert.DeserializeObject<GameFields>(output).ID; 

Let us know if you need further assistance on this.

Narayanasamy P.

Live Chat Icon For mobile
Up arrow icon