Hi all,
I'm trying to show a ListBox with multi-selected values that come from the database. My plan is to build the selectlist in my controller, set the multi-select items in the SelectList then bind it to the ListBox as shown below:
Markup:
<%= Html.ListBox("DaysOfWeek", Model.DaysOfWeek) %>
Controller:
model.ScheduledDays = getListFromDb( ); //ScheduledDays is CSV String (i.e "Mon", "Tue", etc)
string[] scheduledDays = model.ScheduledDays.Split(',');
model.DaysOfWeek is a SelectList of all the days of the week that gets bound to my Html.ListBox above.
for each day in scheduledDays
{
for each item in model.DaysOfWeek (which is my listbox datasource)
{
see if item = day
if so set the item.Selected = true
}
}
But for some reason this doesn't work. Any ideas?
thanks, rod