Why isn't setting the selectedValue in the Selectlist highlighting that value in the browser?

When I do this:

new SelectList(items, dataValueField, dataTextField, items.First());

      

I am getting a SelectList with the item selected (it is inserted as SelectedValue) but not selected.

What do I need to do to get a dropdown combo box where I decide ahead of time which item is selected on page load?

0


source to share


1 answer


Let's say dataFieldValue = "Id", try this:

new SelectList(items, dataValueField, dataTextField, items.First().Id);

      



It looks for a value, not an element.

+1


source







All Articles