/// <summary> /// Determines if the option element is selected. /// </summary> /// <param name="optionElement">The <see cref="OptionElement"/> to test.</param> /// <returns>True if the option is selected, otherwise false.</returns> internal bool IsSelected(OptionElement optionElement) { if (this.MultiValued || this.Options.Any(o => o.GetAttributeValue("selected") != null)) { return(optionElement.GetAttributeValue("selected") != null); } else { return(optionElement.Element == this.Options.First().Element); } }
/// <summary> /// Selects or unselects the option in the select /// </summary> /// <param name="optionElement">The <see cref="OptionElement"/> to select.</param> /// <param name="selected">The selected state of the option. True to select, false to unselect.</param> internal void MakeSelected(OptionElement optionElement, bool selected) { if (!selected) { optionElement.Element.RemoveAttributeCI("selected"); } else { optionElement.Element.SetAttributeValue(XName.Get("selected"), "selected"); if (!this.MultiValued) { foreach (OptionElement option in this.Options) { if (option.Element != optionElement.Element) { option.Element.RemoveAttributeCI("selected"); } } } } }