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));
        }
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Loads text into textbox from value or from 'QueryColumnName' column.
    /// </summary>
    /// <param name="value">Value parameter</param>
    /// <returns>Returns text of options or query</returns>
    private string LoadTextFromData(string value)
    {
        InitOptions();
        txtValue.Editor.ValueIsMacro = false;

        // Options data
        if (!String.IsNullOrEmpty(value))
        {
            lstOptions.SelectedIndex = ListSourceIndex;

            // Get string representation
            SpecialFieldsDefinition def = new SpecialFieldsDefinition(null, FieldInfo, ContextResolver);
            def.LoadFromText(value);
            return(def.ToString());
        }

        // Query selected
        if (ContainsColumn(QueryColumnName))
        {
            string query = ValidationHelper.GetString(Form.Data.GetValue(QueryColumnName), string.Empty).Trim();
            if (!String.IsNullOrEmpty(query))
            {
                lstOptions.SelectedIndex = SqlSourceIndex;
                if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("CMS.Form", "EditSQLQueries"))
                {
                    mDisabledSql = true;
                }
                return(query);
            }
        }

        // Macro data source selected
        if (ContainsColumn(MacroColumnName))
        {
            string macro = ValidationHelper.GetString(Form.Data.GetValue(MacroColumnName), string.Empty).Trim();
            if (!String.IsNullOrEmpty(macro))
            {
                lstOptions.SelectedIndex     = MacroSourceIndex;
                txtValue.Editor.ValueIsMacro = true;

                return(MacroProcessor.RemoveDataMacroBrackets(macro));
            }
        }

        return(null);
    }
    /// <summary>
    /// Loads text into textbox from value or from 'QueryColumnName' column.
    /// </summary>
    /// <param name="value">Value parameter</param>
    /// <returns>Returns text of options or query</returns>
    private string LoadTextFromData(string value)
    {
        InitOptions();

        // Options data
        if (!String.IsNullOrEmpty(value))
        {
            lstOptions.SelectedIndex = ListSourceIndex;

            // Get string representation
            SpecialFieldsDefinition def = new SpecialFieldsDefinition(null, FieldInfo, ContextResolver);
            def.LoadFromText(value);
            return def.ToString();
        }
        // Query selected
        else if (ContainsColumn(QueryColumnName))
        {
            string query = ValidationHelper.GetString(Form.Data.GetValue(QueryColumnName), string.Empty).Trim();
            if (!String.IsNullOrEmpty(query))
            {
                lstOptions.SelectedIndex = SqlSourceIndex;
                if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("CMS.Form", "EditSQLQueries"))
                {
                    disabledSql = true;
                }
                return query;
            }
            // Macro data source selected
            else if (ContainsColumn(MacroColumnName))
            {
                string macro = ValidationHelper.GetString(Form.Data.GetValue(MacroColumnName), string.Empty).Trim();
                if (!String.IsNullOrEmpty(macro))
                {
                    lstOptions.SelectedIndex = MacroSourceIndex;
                    return macro;
                }
            }
        }

        return null;
    }