Ejemplo n.º 1
0
        private static Control CreateDropDownList(Setting setting, bool diagnoseConflictingSettings)
        {
            HtmlGenericControl ctl    = null;
            HtmlGenericControl select = null;

            try
            {
                string valueStr     = setting.Value;
                string currentValue = null;
                select = new HtmlGenericControl("select");

                if (setting.IsConflicting)
                {
                    ctl           = new HtmlGenericControl("option");
                    ctl.InnerHtml = Resources.SettingsControl_SettingValueUndefined;
                    select.Controls.Add(ctl);
                }
                else
                {
                    select.Attributes["id"] = select.Attributes["name"] = string.Concat(ControlIdPrefix, setting.SettingId.ToString("N"));

                    foreach (DataRow row in SettingProvider.GetSettingListValues(setting.SettingId).Rows)
                    {
                        currentValue            = row["Value"].ToString();
                        ctl                     = new HtmlGenericControl("option");
                        ctl.Attributes["value"] = currentValue;
                        if (string.Compare(currentValue, valueStr, StringComparison.CurrentCulture) == 0)
                        {
                            ctl.Attributes["selected"] = "selected";
                        }
                        ctl.InnerHtml = row["Name"].ToString();
                        select.Controls.Add(ctl);
                    }
                }

                if (diagnoseConflictingSettings)
                {
                    select.Disabled = true;
                    select.Style.Add(HtmlTextWriterStyle.Color, "Gray");
                }

                return(select);
            }
            finally
            {
                if (select != null)
                {
                    select.Dispose();
                }
                if (ctl != null)
                {
                    ctl.Dispose();
                }
            }
        }