Пример #1
0
        // internal static void BindListInternal(DropDownList comboBox, object value, IEnumerable listSource, string textField, string valueField)
        internal static void BindListInternal(DnnComboBox comboBox, object value, IEnumerable listSource, string textField, string valueField)
        {
            if (comboBox != null)
            {
                string selectedValue = !comboBox.Page.IsPostBack ? Convert.ToString(value) : comboBox.SelectedValue;

                if (listSource is Dictionary <string, string> )
                {
                    var items = listSource as Dictionary <string, string>;
                    foreach (var item in items)
                    {
                        // comboBox.Items.Add(new ListItem(item.Key, item.Value));
                        comboBox.AddItem(item.Key, item.Value);
                    }
                }
                else
                {
                    comboBox.DataTextField  = textField;
                    comboBox.DataValueField = valueField;
                    comboBox.DataSource     = listSource;

                    comboBox.DataBind();
                }

                // Reset SelectedValue
                // comboBox.Select(selectedValue);
                var selectedItem = comboBox.FindItemByValue(selectedValue);
                if (selectedItem != null)
                {
                    selectedItem.Selected = true;
                }
            }
        }
        //internal static void BindListInternal(DropDownList comboBox, object value, IEnumerable listSource, string textField, string valueField)
        internal static void BindListInternal(DnnComboBox comboBox, object value, IEnumerable listSource, string textField, string valueField)
        {
            if (comboBox != null)
            {
                string selectedValue = !comboBox.Page.IsPostBack ? Convert.ToString(value) : comboBox.SelectedValue;

                if (listSource is Dictionary<string, string>)
                {
                    var items = listSource as Dictionary<string, string>;
                    foreach (var item in items)
                    {
                        //comboBox.Items.Add(new ListItem(item.Key, item.Value));
                        comboBox.AddItem(item.Key, item.Value);
                    }
                }
                else
                {
                    comboBox.DataTextField = textField;
                    comboBox.DataValueField = valueField;
                    comboBox.DataSource = listSource;

                    comboBox.DataBind();
                }

                //Reset SelectedValue
                //comboBox.Select(selectedValue);
                var selectedItem = comboBox.FindItemByValue(selectedValue);
                if (selectedItem != null)
                    selectedItem.Selected = true;                
            }
        }
 private void SelectDropDownListItem(ref DnnComboBox ddl, string key)
 {
     if (Settings.ContainsKey(key))
     {
         ddl.ClearSelection();
         var selItem = ddl.FindItemByValue(Convert.ToString(Settings[key]));
         if (selItem != null)
         {
             selItem.Selected = true;
         }
     }
 }
Пример #4
0
        private void LoadFolders()
        {
            UserInfo user = User ?? UserController.GetCurrentUserInfo();

            FoldersComboBox.Items.Clear();

            //Add Personal Folder
            if (UsePersonalFolder)
            {
                var userFolder = FolderManager.Instance.GetUserFolder(user).FolderPath;
                FoldersComboBox.AddItem(FolderManager.Instance.MyFolderName, userFolder);
            }
            else
            {
                var folders = FolderManager.Instance.GetFolders(PortalId, "READ,ADD", user.UserID);
                foreach (FolderInfo folder in folders)
                {
                    var folderItem = new ListItem
                    {
                        Text =
                            folder.FolderPath == Null.NullString
                                ? "Site Root"
                                : folder.DisplayPath,
                        Value = folder.FolderPath
                    };
                    FoldersComboBox.AddItem(folderItem.Text, folderItem.Value);
                }
            }

            //select folder
            string fileName;
            string folderPath;

            if (!string.IsNullOrEmpty(FilePath))
            {
                fileName   = FilePath.Substring(FilePath.LastIndexOf("/") + 1);
                folderPath = string.IsNullOrEmpty(fileName) ? FilePath : FilePath.Replace(fileName, "");
            }
            else
            {
                fileName   = FilePath;
                folderPath = string.Empty;

                if (UsePersonalFolder)
                {
                    folderPath = FolderManager.Instance.GetUserFolder(user).FolderPath;
                    FilePath   = folderPath;
                }
            }

            if (FoldersComboBox.FindItemByValue(folderPath) != null)
            {
                FoldersComboBox.FindItemByValue(folderPath).Selected = true;
            }

            FolderPath = folderPath;

            //select file
            LoadFiles();

            var fileSelectedItem = FilesComboBox.FindItemByText(fileName);

            if (fileSelectedItem != null)
            {
                fileSelectedItem.Selected = true;
            }
        }