Friday, 27 September 2013

How to iterate through an enumeration of flags and create checkboxes that are checked appropriately for each value?

How to iterate through an enumeration of flags and create checkboxes that
are checked appropriately for each value?

I have an Enum of flags to represent the days of the week, with a few
extra values that indicate weekdays, weekends, every day, or no days.
Here's the Enum:
[Flags]
public enum DayOfWeek : short
{
Sunday = 1,
Monday = 2,
Tuesday = 4,
Wednesday = 8,
Thursday = 16,
Friday = 32,
Saturday = 64,
Weekday = 62,
Weekend = 65,
Everyday = 127,
None = 0
}
I also have a View Model with a property, DayOfWeek with a type of DayOfWeek.
In my View, I need to create a checkbox for each day of the week and
somehow appropriately check the boxes based on which days have been saved.
How can I do this? I'm guessing this needs to be done in a foreach loop,
but that's all I have to go on so far.

No comments:

Post a Comment