/// <summary>
    /// Returns data set depending on specified properties.
    /// </summary>
    /// <param name="ids">ID(s) of the items to load. If null, all items are loaded</param>
    /// <param name="topN">Only take topN items</param>
    /// <param name="pageIndex">Index of the page to get</param>
    /// <param name="offset">Offset of the items</param>
    /// <param name="maxRecords">Maximum number of the records to get</param>
    /// <param name="forceReload">Force reloading of the data</param>
    /// <param name="totalRecords">Returns total number of records</param>
    private DataSet GetResultSet(string ids, int topN, int pageIndex, bool forceReload, int offset, int maxRecords, ref int totalRecords)
    {
        DataSet ds = null;

        // Init columns
        string columns = null;
        if (DisplayNameFormat == USER_DISPLAY_FORMAT)
        {
            // Ensure columns which are needed for USER_DISPLAY_FORMAT
            columns = "UserName;FullName;";
        }
        else if (DisplayNameFormat != null)
        {
            columns = DataHelper.GetNotEmpty(TextHelper.GetMacros(DisplayNameFormat, true), Object.DisplayNameColumn).Replace(";", ", ");
        }
        else
        {
            columns = Object.DisplayNameColumn;
        }

        // Add the default format name column to the query
        if (DefaultDisplayNameFormat != null)
        {
            string defaultColumn = DataHelper.GetNotEmpty(TextHelper.GetMacros(DefaultDisplayNameFormat, true), Object.DisplayNameColumn).Replace(";", ", ");
            columns = SqlHelperClass.MergeColumns(columns, defaultColumn);
        }

        // Add return column name
        columns = SqlHelperClass.MergeColumns(columns, ReturnColumnName);

        // Add additional columns
        columns = SqlHelperClass.MergeColumns(columns, AdditionalColumns);

        // Add enabled column name
        columns = SqlHelperClass.MergeColumns(columns, EnabledColumnName);

        // Add priority column name
        if (PrioritizeItems)
        {
            columns = SqlHelperClass.MergeColumns(columns, "isnull(" + objectType.TypeInfo.PriorityColumn + "," + (int)ObjectPriorityEnum.Low + ") as " + objectType.TypeInfo.PriorityColumn);
        }

        // Ensure SiteID column (for global object prefixes/suffixes)
        if (AddGlobalObjectNamePrefix || AddGlobalObjectSuffix)
        {
            if ((objectType != null) && (objectType.SiteIDColumn != TypeInfo.COLUMN_NAME_UNKNOWN))
            {
                columns = SqlHelperClass.MergeColumns(columns, objectType.SiteIDColumn);
            }
        }

        // Return result set for single selectors
        string itemsWhere = null;

        // Prepare the parameters
        QueryDataParameters parameters = new QueryDataParameters();

        using (var condition = new SelectCondition(parameters))
        {
            switch (SelectionMode)
            {
                case SelectionModeEnum.Multiple:
                case SelectionModeEnum.MultipleButton:
                case SelectionModeEnum.MultipleTextBox:
                    if (ids != null)
                    {
                        // Get where condition for selected items
                        string[] items = ids.Split(ValuesSeparator.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

                        bool isString = !Object.IDColumn.EqualsCSafe(ReturnColumnName, true);
                        if (isString)
                        {
                            // Names
                            condition.Prepare(ReturnColumnName, items, false);
                        }
                        else
                        {
                            // IDs
                            condition.PrepareIDs(ReturnColumnName, items);
                        }

                        // Do not return anything if the selection is empty
                        if (condition.IsEmpty)
                        {
                            return null;
                        }

                        itemsWhere = condition.WhereCondition;
                    }
                    break;

                default:
                    // Build where condition
                    if (!String.IsNullOrEmpty(ids))
                    {
                        itemsWhere = ReturnColumnName + " = '" + SqlHelperClass.GetSafeQueryString(ids, false) + "'";
                    }
                    break;
            }

            // Modify WHERE condition
            string where = SqlHelperClass.AddWhereCondition(this.WhereCondition, itemsWhere);

            // Apply value restrictions
            if (ApplyValueRestrictions)
            {
                where = SqlHelperClass.AddWhereCondition(where, (ListingWhereCondition != String.Empty) ? ListingWhereCondition : WhereCondition);
            }

            // Apply priority restrictions
            if (MinimumPriority != null)
            {
                if (objectType.TypeInfo.PriorityColumn == TypeInfo.COLUMN_NAME_UNKNOWN)
                {
                    throw new GeneralCMSException("Priority column not set in TYPEINFO");
                }
                where = SqlHelperClass.AddWhereCondition(where, objectType.TypeInfo.PriorityColumn + " >= " + MinimumPriority);
            }

            // Apply site restrictions
            string siteWhere = GetSiteWhereCondition();
            if (!string.IsNullOrEmpty(siteWhere))
            {
                where = SqlHelperClass.AddWhereCondition(where, siteWhere);
            }

            // Order by
            string orderBy = String.Empty;

            if (PrioritizeItems)
            {
                orderBy = "isnull(" + objectType.TypeInfo.PriorityColumn + "," + (int)ObjectPriorityEnum.Low + ") DESC,";
            }

            if (String.IsNullOrEmpty(OrderBy))
            {
                orderBy += Object.DisplayNameColumn;
            }
            else
            {
                orderBy += OrderBy;
            }

            GeneralizedInfo obj = ListingObject ?? Object;

            // Get the result set
            ds = obj.GetData(parameters, where, orderBy, topN, columns, false, offset, maxRecords, ref totalRecords);
        }

        return ds;
    }
    /// <summary>
    /// Returns data set depending on specified properties.
    /// </summary>
    private DataSet GetResultSet(string id, int topN, int pageIndex, bool forceReload, int offset, int maxRecords, ref int totalRecords)
    {
        DataSet ds = null;

        // Init columns
        string columns = null;
        if (DisplayNameFormat == USER_DISPLAY_FORMAT)
        {
            // Ensure columns which are needed for USER_DISPLAY_FORMAT
            columns = "UserName;FullName;";
        }
        else if (DisplayNameFormat != null)
        {
            columns = DataHelper.GetNotEmpty(TextHelper.GetMacros(DisplayNameFormat), Object.DisplayNameColumn).Replace(";", ", ");
        }
        else
        {
            columns = Object.DisplayNameColumn;
        }

        // Add the default format name column to the query
        if (DefaultDisplayNameFormat != null)
        {
            string defaultColumn = DataHelper.GetNotEmpty(TextHelper.GetMacros(DefaultDisplayNameFormat), Object.DisplayNameColumn).Replace(";", ", ");
            columns = SqlHelperClass.MergeColumns(columns, defaultColumn);
        }

        // Add return column name
        columns = SqlHelperClass.MergeColumns(columns, ReturnColumnName);

        // Add additional columns
        columns = SqlHelperClass.MergeColumns(columns, AdditionalColumns);

        // Add enabled column name
        columns = SqlHelperClass.MergeColumns(columns, EnabledColumnName);

        // Ensure SiteID column (for global object prefixes/suffixes)
        if (this.AddGlobalObjectNamePrefix || this.AddGlobalObjectSuffix)
        {
            if ((objectType != null) && (objectType.SiteIDColumn != TypeInfo.COLUMN_NAME_UNKNOWN))
            {
                columns = SqlHelperClass.MergeColumns(columns, objectType.SiteIDColumn);
            }
        }

        // Return result set for single selectors
        string itemsWhere = null;

        // Prepare the parameters
        QueryDataParameters parameters = new QueryDataParameters();

        using (var condition = new SelectCondition(parameters))
        {
            if (SelectionMode != SelectionModeEnum.Multiple)
            {
                // Build where condition
                if (!String.IsNullOrEmpty(id))
                {
                    itemsWhere = ReturnColumnName + " = '" + SqlHelperClass.GetSafeQueryString(id, false) + "'";
                }
            }
            // Return result set for multiple selection
            else
            {
                // Get where condition for selected items
                string[] items = hiddenField.Value.Split(ValuesSeparator.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

                bool isString = !Object.IDColumn.Equals(ReturnColumnName, StringComparison.InvariantCultureIgnoreCase);
                if (isString)
                {
                    // Names
                    condition.Prepare(ReturnColumnName, items, false);
                }
                else
                {
                    // IDs
                    condition.PrepareIDs(ReturnColumnName, items);
                }

                // Do not return anything if the selection is empty
                if (condition.IsEmpty)
                {
                    return null;
                }

                itemsWhere = condition.WhereCondition;
            }

            // Modify WHERE condition
            string where = itemsWhere;

            // Apply value restrictions
            if (ApplyValueRestrictions)
            {
                where = SqlHelperClass.AddWhereCondition(where, (ListingWhereCondition != String.Empty) ? ListingWhereCondition : WhereCondition);
            }

            // Order by
            string orderBy = OrderBy;
            if (String.IsNullOrEmpty(orderBy))
            {
                orderBy = Object.DisplayNameColumn;
            }

            GeneralizedInfo obj = (ListingObject == null) ? Object : ListingObject;

            // Get the result set
            ds = obj.GetData(parameters, where, orderBy, topN, columns, false, offset, maxRecords, ref totalRecords);
        }

        return ds;
    }