views:

228

answers:

1

When I do this:

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

I get a SelectList with that item selected (it is inserted as SelectedValue), but not highlighted.

What should I do to get a dropdown with a list where I decide in advance what item is selected when the page loads?

+1  A: 

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

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

It's looking for the value, not the item.

Tim Scott
That did the trick and actually solved a few of my other problems with the selectlist too :)
borisCallens