/// <summary>
    /// Fills existing categories in the drop down list as a tree structure.
    /// </summary>
    /// <param name="shift">Subcategory offset in the DDL</param>
    /// <param name="parentCategoryId">ID of the parent category</param>
    private void FillDropDownList(int shift, int parentCategoryId)
    {
        List <DataRowView> items = gds.GetGroupView(parentCategoryId);

        if (items != null)
        {
            shift++;

            string prefix = "";
            // Prepare prefix
            for (int i = 0; i < shift; i++)
            {
                prefix += SubItemPrefix;
            }

            foreach (DataRowView dr in items)
            {
                ListItem item = new ListItem();

                // Prepend prefix
                item.Text = prefix;

                int    catId          = ValidationHelper.GetInteger(dr["CategoryID"], 0);
                int    catParentId    = ValidationHelper.GetInteger(dr["CategoryParentID"], 0);
                string catDisplayName = ValidationHelper.GetString(dr["CategoryDisplayName"], "");
                bool   catIsSite      = ValidationHelper.GetInteger(dr["CategorySiteID"], 0) > 0;
                bool   catIsEnabled   = ValidationHelper.GetBoolean(dr["CategoryEnabled"], true);

                if (!AllowDisabledCategories)
                {
                    // Category stays enabled only if its parent is enabled
                    if (catIsEnabled)
                    {
                        catIsEnabled = !disabledCats.ContainsKey(catParentId);
                    }

                    // Add disabled category to disabled list
                    if (!catIsEnabled && !disabledCats.ContainsKey(catId))
                    {
                        disabledCats.Add(catId, null);
                    }
                }

                item.Text += ResHelper.LocalizeString(catDisplayName);
                item.Value = catId.ToString();

                // Add item to the DLL
                drpCategories.Items.Add(item);

                // Disable unwanted site categories and unwanted disabled categories
                if ((!AllowDisabledCategories && !catIsEnabled) || (DisableSiteCategories && catIsSite))
                {
                    DisableItem(item);
                }

                // Call to add the subitems
                FillDropDownList(shift, catId);
            }
        }
    }
Example #2
0
    /// <summary>
    /// Fills existing UIElements in the drop down list as a tree structure.
    /// </summary>
    /// <param name="shift">Subelement offset in the DDL</param>
    /// <param name="parentCategoryID">ID of the parent element</param>
    protected void FillDropDownList(int shift, int parentElementId)
    {
        List <DataRowView> items = null;

        items = gds.GetGroupView(parentElementId);

        if (items != null)
        {
            shift++;

            foreach (DataRowView dr in items)
            {
                ListItem item = new ListItem();

                // Append prefix
                for (int i = 0; i < shift; i++)
                {
                    item.Text += SubItemPrefix;
                }

                int    elementId          = ValidationHelper.GetInteger(dr["ElementID"], 0);
                string elementName        = ValidationHelper.GetString(dr["ElementDisplayName"], "");
                string elementDisplayName = ValidationHelper.GetString(dr["ElementDisplayName"], "");

                item.Text += ResHelper.LocalizeString(elementDisplayName);
                item.Value = elementId.ToString();

                // Add item to the DLL
                drpElements.Items.Add(item);

                // Call to add the subitems
                FillDropDownList(shift, elementId);
            }
        }
    }
    /// <summary>
    /// Fills existing SettingsCategories in the DropDownList as a tree structure.
    /// </summary>
    /// <param name="shift">Sub element offset in the DropDownList</param>
    /// <param name="parentCategoryID">ID of the parent Category</param>
    private void FillDropDownList(int shift, int parentCategoryID)
    {
        List <DataRowView> items = null;

        if (parentCategoryID > 0)
        {
            items = groupedDS.GetGroupView(parentCategoryID);
        }
        else
        {
            items = groupedDS.GetGroupView(DBNull.Value);
        }
        if (items != null)
        {
            shift++;

            foreach (DataRowView dr in items)
            {
                int cID = ValidationHelper.GetInteger(dr["CategoryID"], 0);

                // Skip processing for current category, current category and its children should not be displayed
                // in the DropDownList
                bool skipCurrent = ((CurrentCategoryId > 0) && (CurrentCategoryId == cID));
                if (skipCurrent)
                {
                    continue;
                }
                string cName        = ValidationHelper.GetString(dr["CategoryName"], "");
                string cDisplayName = ValidationHelper.GetString(dr["CategoryDisplayName"], "");
                bool   cIsGroup     = ValidationHelper.GetBoolean(dr["CategoryIsGroup"], false);

                // Init item
                ListItem item = new ListItem();
                item.Text  = GetPrefix(shift) + ResHelper.LocalizeString(cDisplayName);
                item.Value = cID.ToString();

                // Add item to the DropDownList
                drpCategories.Items.Add(item);

                // Disable item if in key-edit mode and item represents category
                DisableItemInKeyEdit(item, cIsGroup);

                // Call to add the sub items
                FillDropDownList(shift, cID);
            }
        }
    }