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

SfAutocomplete bind integer while searching and displaying string value


I am trying to sue SfAutocomplete for this very basic use case and it doesn't seem to work.

Basically I am trying to have an autocomplete field where I can search by name, the dropdown with matching results should also display the user name and once I select it should save the UserId associated with that user.

The documentation shows an example where it uses a "string" but I feel in at least 90% of the cases one needs to store an int instead. I'd like to make this default behavior work without having to add other events like onchange, etc.

FilteredTeamMembers is defined as List that contains a User attribute. I populate this List async from the DB when the page loads.

The form I am trying to bind is the following

In my @code section I declare the FormProjectUser variable as follows:

public frm_ProjectUser FormProjectuser { get; set; } = new frm_ProjectUser();

I've been struggling to make this work sometimes the page doesn't even load without giving me any error and after other attempts I've been able to store the ID to a different variable (not the form) but to do that I have to search by User ID and the dropdown displays the Full Name, when I select an item it stores the ID. This is obviously not the ideal scenario as the user needs to search by name.

1 Reply

SP Sureshkumar P Syncfusion Team February 23, 2023 06:23 AM UTC

Hi Ivan,

We suspect that you want to be filtering the autocomplete component data using the text field. By default, the search and filter work based on the Value field alone in the AutoComplete component. The mapping text field for AutoComplete will only update the text to list items in the popup but functionalities like sorting and filtering will be performed based on the value field. So, you can bind only the value field based on the component design. 

To know more about how to filter more than one data field to refer the public forum answers: https://www.syncfusion.com/forums/164193/how-to-filter-on-more-than-one-data-field-in-blazor-autocomplete

Else, you can use our combobox component which is used to map both text and value fields for the component. Please find the demo and documentation in the below link.

Demo https://blazor.syncfusion.com/demos/combobox/default-functionalities?theme=fluent

Documentation: https://blazor.syncfusion.com/documentation/combobox/getting-started


Sureshkumar P

Live Chat Icon For mobile
Up arrow icon