views:

15

answers:

1

There are times where I would like to take the SelectedList and ask for the Text item that has been selected. So using the example:

SelectList sl = new SelectList( new[]{
  new SelectListItem{ Text="one", Value="1"},
  new SelectListItem{ Text="two", Value="2"},
  new SelectListItem{ Text="three", Value="3"}
}, "Text", "Value", "2" );

How do I now ask the sl for the SelectedItem.Text ? I am surprised there isn't an is a method to do this, or atleast one I can see. Any suggestions? Do I need to IQuery or IEnumerate this in some fashion to make it happen ?

A: 

Are you searching for the SelectedValue-Method

?

Mark
Not sure.... if tis was a List, I'd say sl.Items[selected].text; or something like that. For multi select I'd do for i = 0 to sl.items.count-1 do if sl.items[i].selected then ...
sry that i first now are answering i was on holidays. Have you tried to get your selected item by sl.SelectedValue ? It should be that what your trying
Mark