/// <summary> /// Loads and selects control. /// </summary> private void LoadAndSelectList() { if (dropDownList.Items.Count == 0) { string options = GetResolvedValue <string>("options", null); string query = ValidationHelper.GetString(GetValue("query"), null); string macro = MacroSource; try { if (string.IsNullOrEmpty(macro)) { // Load from options or query FormHelper.LoadItemsIntoList(options, query, dropDownList.Items, FieldInfo, ContextResolver, SortItems); } else { // Load from macro source var def = new SpecialFieldsDefinition(null, FieldInfo, ContextResolver, SortItems); def.LoadFromMacro(macro, ValueFormat, TextFormat); def.FillItems(dropDownList.Items); } } catch (Exception ex) { DisplayException(ex); } FormHelper.SelectSingleValue(mSelectedValue, dropDownList, true); } }
private void LoadAndSelectList(bool forceReload = false) { lbOptions.SelectionMode = AllowMultiple ? ListSelectionMode.Multiple : ListSelectionMode.Single; if (forceReload) { // Keep selected value _selectedValues = lbOptions.Items.Cast <ListItem>().Where(x => x.Selected).Select(x => x.Value).ToList(); // Clears values if forced reload is requested lbOptions.Items.Clear(); } if (lbOptions.Items.Count == 0) { try { var def = new SpecialFieldsDefinition(null, FieldInfo, ContextResolver, SortItems); if (string.IsNullOrEmpty(MacroSource)) { if (string.IsNullOrEmpty(QuerySource)) { // Load from text source def.LoadFromText(Options); } else { // Load from query source def.LoadFromQuery(QuerySource); } } else { // Load from macro source def.LoadFromMacro(MacroSource, ValueFormat, TextFormat); } def.FillItems(lbOptions.Items); } catch (Exception ex) { DisplayException(ex); } foreach (ListItem lbOptionsItem in lbOptions.Items) { if (_selectedValues != null && _selectedValues.Contains(lbOptionsItem.Value)) { lbOptionsItem.Selected = true; } } lbOptions.Items.Insert(0, new ListItem(String.Empty, String.Empty)); } }
/// <summary> /// Loads and selects control. /// </summary> private void LoadAndSelectList() { if (dropDownList.Items.Count == 0) { string options = GetResolvedValue<string>("options", null); string query = ValidationHelper.GetString(GetValue("query"), null); string macro = MacroSource; try { if (string.IsNullOrEmpty(macro)) { // Load from options or query FormHelper.LoadItemsIntoList(options, query, dropDownList.Items, FieldInfo, ContextResolver, SortItems); } else { // Load from macro source var def = new SpecialFieldsDefinition(null, FieldInfo, ContextResolver, SortItems); def.LoadFromMacro(macro, ValueFormat, TextFormat); def.FillItems(dropDownList.Items); } } catch (Exception ex) { DisplayException(ex); } FormHelper.SelectSingleValue(mSelectedValue, dropDownList, true); } }