/// <summary> /// Fills dropdown with data. /// </summary> /// <param name="parentID">Identifier of node which children you want to add</param> /// <param name="level">Level of indentation</param> private void FillDropDown(int parentID, int level) { if (GroupedCategories != null) { List <DataRowView> gCategory = GroupedCategories.GetGroup(parentID); if (gCategory != null) { var categoryTypeInfo = CategoryInfo.TypeInfo; foreach (DataRowView drCategory in gCategory) { if (!ExcludedItems.Contains(ValidationHelper.GetInteger(drCategory[categoryTypeInfo.IDColumn], 0))) { string name = ResHelper.LocalizeString(drCategory[CategoryInfo.Generalized.DisplayNameColumn].ToString()); int categoryId = ValidationHelper.GetInteger(drCategory[categoryTypeInfo.IDColumn], 0); List <DataRowView> objectGroup = ((!ShowEmptyCategories || ShowObjects) && GroupedObjects != null) ? GroupedObjects.GetGroup(drCategory[categoryTypeInfo.IDColumn]) : null; List <DataRowView> childCategoryGroup = !ShowEmptyCategories?GroupedCategories.GetGroup(categoryId) : null; // Check for empty categories except the root if ((level == 0) || ShowEmptyCategories || ((objectGroup != null) && (objectGroup.Count > 0)) || ((childCategoryGroup != null) && (childCategoryGroup.Count > 0))) { bool enabled = true; // Resolve Enabled condition if (!String.IsNullOrEmpty(EnabledCondition)) { MacroResolver.SetAnonymousSourceData(drCategory); enabled = ValidationHelper.GetBoolean(MacroResolver.ResolveMacros(EnabledCondition), true); } string indentation = String.Empty; if ((level > 0) || ShowRoot) { // Create indentation for specified level indentation = String.Concat(Enumerable.Repeat(SubItemPrefix, ShowRoot ? level : level - 1)); string value = ((level == 0) && (RootValue > 0) ? RootValue : categoryId).ToString(); // Prevent category list item to be selected by ID when selecting object if (ShowObjects) { value = "cat_" + value; } // Insert category ListItem listItem = new ListItem(indentation + ResHelper.LocalizeString(name), value); if (ShowObjects || DisabledItems.Contains(categoryId) || !enabled) { listItem.Attributes.Add("style", DisabledItemStyle); listItem.Attributes.Add("disabled", "disabled"); } else { if (!firstItem && String.IsNullOrEmpty(mSelectedValue)) { SetItem(parentID, value); } } drpCategory.Items.Add(listItem); } // Go deeper FillDropDown(categoryId, level + 1); // Insert all child objects if needed if (ShowObjects && !DataHelper.DataSourceIsEmpty(objectGroup)) { if (objectGroup != null) { indentation += SubItemPrefix; foreach (DataRowView childObject in objectGroup) { string text = indentation + ResHelper.LocalizeString(childObject[ObjectInfo.Generalized.DisplayNameColumn].ToString()); string objValue = childObject[ObjectInfo.TypeInfo.IDColumn].ToString(); drpCategory.Items.Add(new ListItem(text, objValue)); if (!firstItem && String.IsNullOrEmpty(mSelectedValue)) { SetItem(parentID, objValue); } } } } } } } } } }
protected bool IsEnabled(string id) { return(!DisabledItems.Contains(id)); }