List all Checkbox List options/Compare two lists within one foreach.
I'm using a checkbox list to select "active months" and then highlight those active months within a section that lists all the months. I can't find a way to list all the months in the checklist within the same foreach loop, but change the styles for the selected months.
So, I'm listing months January through December and if the user selects April, May, and June, I want the styles for those months to change - bold instead of regular font, for example. So I'd want it to look like this:
(Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec)
And I can hard-code all the months into a list that can then be iterated through with a foreach, but I don't know how to apply the selected month information to the full list of months in a way that keeps everything within the same section and only changes styling.
Yes, in my foreach loop I need to detect which months are selected on the page and then change the styling of those months.
Currently I can loop through the months, which are written directly into a list in my code since I can't find a way to detect the non-selected months from the checkbox list. That's how I get the full list of months from January to December.
I can also foreach through the selected checkbox values with
List<String> monthList = Model.Value<IEnumerable<string>>("monthSelect").ToList();
foreach (var month in monthList)
{
@*do something with month*@
}
But I don't know what code I need to use to essentially say "If a month in the Full List is the same in Selected List, change the class, while still listing out every month, in order, as if foreach looping through the Full List."
List all Checkbox List options/Compare two lists within one foreach.
I'm using a checkbox list to select "active months" and then highlight those active months within a section that lists all the months. I can't find a way to list all the months in the checklist within the same foreach loop, but change the styles for the selected months.
So, I'm listing months January through December and if the user selects April, May, and June, I want the styles for those months to change - bold instead of regular font, for example. So I'd want it to look like this:
(Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec)
I can get the selected months with:
And I can hard-code all the months into a list that can then be iterated through with a foreach, but I don't know how to apply the selected month information to the full list of months in a way that keeps everything within the same section and only changes styling.
HI mizzle
Not 100% sure what you mean. However, is it that in your foreach loop you need to change the styling of selected months?
If so, when iterating over your foreach loop can you set a class on the checkbox as active, and CSS you can then make that set to be bold.
Sorry if I'm not understanding correctly.
Could you share the foreach loop you have so far?
Yes, in my foreach loop I need to detect which months are selected on the page and then change the styling of those months.
Currently I can loop through the months, which are written directly into a list in my code since I can't find a way to detect the non-selected months from the checkbox list. That's how I get the full list of months from January to December.
I can also foreach through the selected checkbox values with
But I don't know what code I need to use to essentially say "If a month in the Full List is the same in Selected List, change the class, while still listing out every month, in order, as if foreach looping through the Full List."
is working on a reply...