Пример #1
0
 void gridElem_OnFilterFieldCreated(string columnName, UniGridFilterField filterDefinition)
 {
     filter = filterDefinition.ValueControl as ContactFilter;
     if (filter != null)
     {
         filter.IsLiveSite = IsLiveSite;
     }
 }
Пример #2
0
 void gridElem_OnFilterFieldCreated(string columnName, UniGridFilterField filterDefinition)
 {
     filter = filterDefinition.ValueControl as CMSModules_ContactManagement_Controls_UI_Account_Filter;
     if (filter != null)
     {
         filter.IsLiveSite = IsLiveSite;
     }
 }
Пример #3
0
 void gridElem_OnFilterFieldCreated(string columnName, UniGridFilterField filterDefinition)
 {
     filter = filterDefinition.ValueControl as CMSModules_ContactManagement_Controls_UI_Account_Filter;
     if (filter != null)
     {
         filter.NotMerged          = true;
         filter.IsLiveSite         = IsLiveSite;
         filter.ShowGlobalStatuses = ConfigurationHelper.AuthorizedReadConfiguration(UniSelector.US_GLOBAL_RECORD, false);
     }
 }
Пример #4
0
 private void gridElem_OnFilterFieldCreated(string columnName, UniGridFilterField filterDefinition)
 {
     mFilter = filterDefinition.ValueControl as ContactFilter;
     if (mFilter != null)
     {
         mFilter.NotMerged        = true;
         mFilter.HideMergedFilter = true;
         mFilter.IsLiveSite       = IsLiveSite;
     }
 }
Пример #5
0
    void gridElem_OnFilterFieldCreated(string columnName, UniGridFilterField filterDefinition)
    {
        var filter = filterDefinition.ValueControl as CMSModules_ContactManagement_Controls_UI_Activity_Filter;

        if (filter != null)
        {
            filter.ShowContactSelector = ShowContactNameColumn;
            filter.ShowSiteFilter      = ShowSiteNameColumn;
            filter.ShowIPFilter        = ShowIPAddressColumn;
        }
    }
    void gridElem_OnFilterFieldCreated(string columnName, UniGridFilterField filterDefinition)
    {
        var filter = filterDefinition.ValueControl as CMSModules_ContactManagement_Controls_UI_Account_Filter;

        if (filter != null)
        {
            filter.NotMerged            = true;
            filter.DisplayAccountStatus = true;
            filter.SiteID     = SiteID;
            filter.IsLiveSite = IsLiveSite;
        }
    }
Пример #7
0
 protected void ugRecycleBin_OnFilterFieldCreated(string columnName, UniGridFilterField filterDefinition)
 {
     filter = filterDefinition.ValueControl as CMSAbstractRecycleBinFilterControl;
     if (filter != null)
     {
         filter.DisplayDateTimeFilter = DisplayDateTimeFilter;
         // If filter is set
         if (filter.FilterIsSet)
         {
             ugRecycleBin.ZeroRowsText = GetString("unigrid.filteredzerorowstext");
         }
         else
         {
             ugRecycleBin.ZeroRowsText = IsSingleSite ? GetString("RecycleBin.NoDocuments") : GetString("RecycleBin.Empty");
         }
     }
 }
    /// <summary>
    /// Validates filter field input and returns error message.
    /// </summary>
    /// <param name="filterField">UniGridFilterField which will be validated</param>
    private string ValidateFilterField(UniGridFilterField filterField)
    {
        string value = string.Empty;

        // Try to get value from filter textbox
        TextBox valueControl = filterField.ValueControl as TextBox;
        if (valueControl != null)
        {
            value = valueControl.Text;
        }

        // Validate value
        if (!string.IsNullOrEmpty(value))
        {
            switch (filterField.Type)
            {
                case UniGridFilterTypeEnum.Bool:
                    return ValidationHelper.IsBoolean(value) ? string.Empty : GetString("filter.validboolean");
                case UniGridFilterTypeEnum.Integer:
                    return ValidationHelper.IsInteger(value) ? string.Empty : GetString("filter.validintergernumber");
                case UniGridFilterTypeEnum.Double:
                    return ValidationHelper.IsDouble(value) ? string.Empty : GetString("filter.validdecimalnumber");
                default:
                    return string.Empty;
            }
        }
        return string.Empty;
    }
    /// <summary>
    /// Load options definition.
    /// </summary>
    /// <param name="options">Options configuration</param>
    /// <param name="filterWrapperControl">Wrapper control for filter</param>
    private void LoadOptionsDefinition(UniGridOptions options, Control filterWrapperControl)
    {
        // Add custom filter or filter wrapper panel according to the key value "DisplayFilter"
        displayFilter = options.DisplayFilter;

        if (displayFilter)
        {
            // Add custom filter
            if (!mCustomFilterAdded && !string.IsNullOrEmpty(options.FilterPath))
            {
                UniGridFilterField filterDefinition = new UniGridFilterField();
                CMSAbstractBaseFilterControl filterControl = LoadFilterControl(options.FilterPath, CUSTOM_FILTER_SOURCE_NAME, null, filterDefinition);
                FilterFields[CUSTOM_FILTER_SOURCE_NAME] = filterDefinition;
                mCustomFilterAdded = true;

                plcFilter.Controls.Add(filterControl);

                RaiseOnFilterFieldCreated(null, filterDefinition);
            }
            // Add wrapper panel for default filter
            else
            {
                plcFilter.Controls.Add(filterWrapperControl);
            }
        }

        // Filter limit
        if (options.FilterLimit > -1)
        {
            FilterLimit = options.FilterLimit;
        }

        // Display sort direction images
        showSortDirection = options.ShowSortDirection;

        // Display selection column with checkboxes
        showSelection = options.ShowSelection;
        if (showSelection)
        {
            TemplateField chkColumn = new TemplateField();

            using (CMSCheckBox headerBox = new CMSCheckBox
            {
                ID = "headerBox"
            })
            {
                using (CMSCheckBox itemBox = new CMSCheckBox
                {
                    ID = "itemBox"
                })
                {
                    // Set selection argument
                    itemBox.Attributes["selectioncolumn"] = options.SelectionColumn;
                    chkColumn.HeaderTemplate = new GridViewTemplate(ListItemType.Header, this, headerBox);
                    chkColumn.ItemTemplate = new GridViewTemplate(ListItemType.Item, this, itemBox);
                }
            }
            GridView.Columns.Add(chkColumn);
        }

        // PageSize and DisplayPageSizeDropdown properties are obsolete.
        // This code ensures backward compatibility.
        // #pragma statement disables warnings for using obsolete attribute.
        #pragma warning disable 612, 618
        if (!String.IsNullOrEmpty(options.PageSize))
        {
            Pager.PageSizeOptions = options.PageSize;
        }

        // Set paging according to the key value "DisplayPageSizeDropdown"
        if (options.DisplayPageSizeDropdown != null)
        {
            Pager.ShowPageSize = options.DisplayPageSizeDropdown.Value;
        }
        #pragma warning restore 612, 618
    }
    /// <summary>
    /// Loads the filter control
    /// </summary>
    /// <param name="path">Control path</param>
    /// <param name="fieldSourceName">Field source name</param>
    /// <param name="value">Field value</param>
    /// <param name="filterDefinition">Filter definition</param>
    /// <param name="filterColumn">Filter column</param>    
    private CMSAbstractBaseFilterControl LoadFilterControl(string path, string fieldSourceName, string value, UniGridFilterField filterDefinition, ColumnFilter filterColumn = null)
    {
        string fullPath = (path.StartsWithCSafe("~/") ? path : FilterDirectoryPath + path.TrimStart('/'));

        // Load the filter control
        CMSAbstractBaseFilterControl filterControl = LoadUserControl(fullPath) as CMSAbstractBaseFilterControl;
        if (filterControl != null)
        {
            // Setup the filter control
            filterControl.ID = fieldSourceName;
            filterControl.FilteredControl = this;

            if (!RequestHelper.IsPostBack())
            {
                filterControl.Value = value;
            }

            filterDefinition.ValueControl = filterControl;
            filterDefinition.ControlPath = path;

            ISimpleDataContainer filterSimpleDataContainer = filterControl as ISimpleDataContainer;
            // If filter control is ISimpleDataContainer we can set specified parameters if they are provided
            if (filterColumn != null &&
                filterSimpleDataContainer != null &&
                filterColumn.CustomFilterParameters != null &&
                filterColumn.CustomFilterParameters.Parameters != null)
            {
                filterColumn.CustomFilterParameters.Parameters.ForEach(parameter => filterSimpleDataContainer.SetValue(parameter.Name, parameter.Value));
            }
        }

        return filterControl;
    }
    /// <summary>
    /// Add filter field to the filter table.
    /// </summary>
    /// <param name="filter">Filter definition</param>
    /// <param name="columnSourceName">Column source field name</param>
    /// <param name="fieldDisplayName">Field display name</param>
    /// <param name="filterWrapperControl">Wrapper control for filter</param>
    /// <param name="filterValue">Filter value</param>
    private void AddFilterField(ColumnFilter filter, string columnSourceName, string fieldDisplayName, Control filterWrapperControl, string filterValue)
    {
        string fieldSourceName = filter.Source ?? columnSourceName;
        if (String.IsNullOrEmpty(fieldSourceName) || (filter == null) || (filterWrapperControl == null))
        {
            return;
        }

        string fieldPath = filter.Path;
        string filterFormat = filter.Format;
        int filterSize = filter.Size;
        Unit filterWidth = filter.Width;

        Panel fieldWrapperPanel = new Panel()
        {
            CssClass = "form-group"
        };

        Panel fieldLabelPanel = new Panel()
        {
            CssClass = "filter-form-label-cell"
        };

        Panel fieldOptionPanel = new Panel()
        {
            CssClass = "filter-form-condition-cell"
        };

        Panel fieldInputPanel = new Panel()
        {
            CssClass = "filter-form-value-cell"
        };

        // Ensure fieldSourceName is JavaScript valid
        fieldSourceName = fieldSourceName.Replace(ALL, "__ALL__");

        int index = GetNumberOfFilterFieldsWithSameSourceColumn(fieldSourceName);
        string filterControlID = fieldSourceName + (index > 0 ? index.ToString() : String.Empty);

        Label textName = new Label
        {
            Text = String.IsNullOrEmpty(fieldDisplayName) ? String.Empty : fieldDisplayName + ":",
            ID = String.Format("{0}Name", filterControlID),
            EnableViewState = false,
            CssClass = "control-label"
        };

        fieldLabelPanel.Controls.Add(textName);
        fieldWrapperPanel.Controls.Add(fieldLabelPanel);

        // Filter value
        string value = null;
        if (filterValue != null)
        {
            value = ValidationHelper.GetString(filterValue, null);
        }

        // Filter definition
        UniGridFilterField filterDefinition = new UniGridFilterField();
        filterDefinition.Type = filter.Type;
        filterDefinition.Label = textName;
        filterDefinition.Format = filterFormat;
        filterDefinition.FilterRow = fieldWrapperPanel;

        // Set the filter default value
        string defaultValue = filter.DefaultValue;

        // Remember default values of filter field controls for potential UniGrid reset
        string optionFilterFieldValue = null;
        string valueFilterFieldValue = null;

        switch (filterDefinition.Type)
        {
            // Text filter
            case UniGridFilterTypeEnum.Text:
                {
                    CMSDropDownList textOptionFilterField = new CMSDropDownList();
                    ControlsHelper.FillListWithTextSqlOperators(textOptionFilterField);
                    textOptionFilterField.ID = filterControlID;

                    // Set the value
                    SetDropdownValue(value, null, textOptionFilterField);
                    optionFilterFieldValue = textOptionFilterField.SelectedValue;

                    LocalizedLabel lblSelect = new LocalizedLabel
                    {
                        EnableViewState = false,
                        CssClass = "sr-only",
                        AssociatedControlID = textOptionFilterField.ID,
                        ResourceString = "filter.mode"
                    };

                    fieldOptionPanel.Controls.Add(lblSelect);
                    fieldOptionPanel.Controls.Add(textOptionFilterField);
                    fieldWrapperPanel.Controls.Add(fieldOptionPanel);

                    CMSTextBox textValueFilterField = new CMSTextBox
                    {
                        ID = String.Format("{0}TextValue", filterControlID)
                    };

                    // Set value
                    SetTextboxValue(value, defaultValue, textValueFilterField);
                    valueFilterFieldValue = textValueFilterField.Text;

                    if (filterSize > 0)
                    {
                        textValueFilterField.MaxLength = filterSize;
                    }
                    if (!filterWidth.IsEmpty)
                    {
                        textValueFilterField.Width = filterWidth;
                    }
                    fieldInputPanel.Controls.Add(textValueFilterField);
                    fieldWrapperPanel.Controls.Add(fieldInputPanel);
                    textName.AssociatedControlID = textValueFilterField.ID;

                    filterDefinition.OptionsControl = textOptionFilterField;
                    filterDefinition.ValueControl = textValueFilterField;
                }
                break;

            // Boolean filter
            case UniGridFilterTypeEnum.Bool:
                {
                    CMSDropDownList booleanOptionFilterField = new CMSDropDownList();

                    booleanOptionFilterField.Items.Add(new ListItem(GetString("general.selectall"), String.Empty));
                    booleanOptionFilterField.Items.Add(new ListItem(GetString("general.yes"), "1"));
                    booleanOptionFilterField.Items.Add(new ListItem(GetString("general.no"), "0"));
                    booleanOptionFilterField.ID = filterControlID;
                    textName.AssociatedControlID = booleanOptionFilterField.ID;

                    // Set the value
                    SetDropdownValue(value, defaultValue, booleanOptionFilterField);
                    valueFilterFieldValue = booleanOptionFilterField.SelectedValue;

                    // Set input panel wide for boolean Drop-down list
                    fieldInputPanel.CssClass = "filter-form-value-cell-wide";

                    fieldInputPanel.Controls.Add(booleanOptionFilterField);
                    fieldWrapperPanel.Controls.Add(fieldInputPanel);

                    filterDefinition.ValueControl = booleanOptionFilterField;
                }
                break;

            // Integer filter
            case UniGridFilterTypeEnum.Integer:
            case UniGridFilterTypeEnum.Double:
                {
                    CMSDropDownList numberOptionFilterField = new CMSDropDownList();
                    numberOptionFilterField.Items.Add(new ListItem(GetString("filter.equals"), "="));
                    numberOptionFilterField.Items.Add(new ListItem(GetString("filter.notequals"), "<>"));
                    numberOptionFilterField.Items.Add(new ListItem(GetString("filter.lessthan"), "<"));
                    numberOptionFilterField.Items.Add(new ListItem(GetString("filter.greaterthan"), ">"));
                    numberOptionFilterField.ID = filterControlID;

                    // Set the value
                    SetDropdownValue(value, null, numberOptionFilterField);
                    optionFilterFieldValue = numberOptionFilterField.SelectedValue;

                    LocalizedLabel lblSelect = new LocalizedLabel
                    {
                        EnableViewState = false,
                        CssClass = "sr-only",
                        AssociatedControlID = numberOptionFilterField.ID,
                        ResourceString = "filter.mode"
                    };

                    // Add filter field
                    fieldOptionPanel.Controls.Add(lblSelect);
                    fieldOptionPanel.Controls.Add(numberOptionFilterField);
                    fieldWrapperPanel.Controls.Add(fieldOptionPanel);

                    CMSTextBox numberValueFilterField = new CMSTextBox
                    {
                        ID = String.Format("{0}NumberValue", filterControlID)
                    };

                    // Set value
                    SetTextboxValue(value, defaultValue, numberValueFilterField);
                    valueFilterFieldValue = numberValueFilterField.Text;

                    if (filterSize > 0)
                    {
                        numberValueFilterField.MaxLength = filterSize;
                    }
                    if (!filterWidth.IsEmpty)
                    {
                        numberValueFilterField.Width = filterWidth;
                    }
                    numberValueFilterField.EnableViewState = false;

                    fieldInputPanel.Controls.Add(numberValueFilterField);
                    fieldWrapperPanel.Controls.Add(fieldInputPanel);

                    filterDefinition.OptionsControl = numberOptionFilterField;
                    filterDefinition.ValueControl = numberValueFilterField;
                }
                break;

            case UniGridFilterTypeEnum.Site:
                {
                    // Site selector
                    fieldPath = "~/CMSFormControls/Filters/SiteFilter.ascx";
                }
                break;

            case UniGridFilterTypeEnum.Custom:
                // Load custom path
                {
                    if (String.IsNullOrEmpty(fieldPath))
                    {
                        throw new Exception("[UniGrid.AddFilterField]: Filter field path is not set");
                    }
                }
                break;

            default:
                // Not supported filter type
                throw new Exception("[UniGrid.AddFilterField]: Filter type '" + filterDefinition.Type + "' is not supported. Supported filter types: integer, double, bool, text, site, custom.");
        }

        // Else if filter path is defined use custom filter
        if (fieldPath != null)
        {
            // Add to the controls collection
            CMSAbstractBaseFilterControl filterControl = LoadFilterControl(fieldPath, filterControlID, value, filterDefinition, filter);
            if (filterControl != null)
            {
                // Set default value
                if (!String.IsNullOrEmpty(defaultValue))
                {
                    filterControl.SelectedValue = defaultValue;
                }

                fieldInputPanel.Controls.Add(filterControl);
            }

            fieldInputPanel.CssClass = "filter-form-value-cell-wide";
            fieldWrapperPanel.Controls.Add(fieldInputPanel);
        }

        RaiseOnFilterFieldCreated(fieldSourceName, filterDefinition);
        FilterFields[String.Format("{0}{1}", fieldSourceName, (index > 0 ? "#" + index : String.Empty))] = filterDefinition;

        filterWrapperControl.Controls.Add(fieldWrapperPanel);

        // Store initial filter state for potential UniGrid reset
        if (filterDefinition.OptionsControl != null)
        {
            InitialFilterStateControls.Add(new KeyValuePair<Control, object>(filterDefinition.OptionsControl, optionFilterFieldValue));
        }
        if (filterDefinition.ValueControl != null)
        {
            if (!(filterDefinition.ValueControl is CMSAbstractBaseFilterControl))
            {
                InitialFilterStateControls.Add(new KeyValuePair<Control, object>(filterDefinition.ValueControl, valueFilterFieldValue));
            }
        }
    }
Пример #12
0
 private void gridElem_OnFilterFieldCreated(string columnName, UniGridFilterField filterDefinition)
 {
     filter = filterDefinition.ValueControl as CMSModules_ContactManagement_Controls_UI_Activity_Filter;
 }
Пример #13
0
 void gridElem_OnFilterFieldCreated(string columnName, UniGridFilterField filterDefinition)
 {
     filter = filterDefinition.ValueControl as CMSModules_ContactManagement_Controls_UI_IP_Filter;
 }
    /// <summary>
    /// Loads the filter control
    /// </summary>
    /// <param name="fieldPath">Field path</param>
    /// <param name="fieldSourceName">Field source name</param>
    /// <param name="value">Field value</param>
    /// <param name="filterDefinition">Filter definition</param>
    /// <param name="path">Control path</param>
    private CMSAbstractBaseFilterControl LoadFilterControl(string fieldPath, string fieldSourceName, string value, UniGridFilterField filterDefinition, string path)
    {
        // Load the filter control
        CMSAbstractBaseFilterControl filterControl = this.LoadUserControl(path) as CMSAbstractBaseFilterControl;
        if (filterControl != null)
        {
            // Setup the filter control
            filterControl.ID = fieldSourceName;
            filterControl.FilteredControl = this;

            if (!RequestHelper.IsPostBack())
            {
                filterControl.Value = value;
            }

            filterDefinition.ValueControl = filterControl;
            filterDefinition.ControlPath = fieldPath;
        }

        return filterControl;
    }
 void gridElem_OnFilterFieldCreated(string columnName, UniGridFilterField filterDefinition)
 {
     filter = filterDefinition.ValueControl as CMSModules_ContactManagement_Controls_UI_Contact_Filter;
     if (filter != null)
     {
         filter.HideMergedFilter = true;
         filter.IsLiveSite = IsLiveSite;
     }
 }
 void gridElem_OnFilterFieldCreated(string columnName, UniGridFilterField filterDefinition)
 {
     filter = filterDefinition.ValueControl as ContactFilter;
     if (filter != null)
     {
         filter.NotMerged = true;
         filter.HideMergedFilter = true;
         filter.IsLiveSite = IsLiveSite;
     }
 }
Пример #17
0
 private void gridElem_OnFilterFieldCreated(string columnName, UniGridFilterField filterDefinition)
 {
     filter = filterDefinition.ValueControl as CMSModules_Activities_Controls_UI_Activity_Filter;
 }
Пример #18
0
 void gridElem_OnFilterFieldCreated(string columnName, UniGridFilterField filterDefinition)
 {
     var filter = filterDefinition.ValueControl as CMSModules_ContactManagement_Controls_UI_IP_Filter;
     if (filter != null)
     {
         filter.ShowContactNameFilter = ShowContactNameColumn;
         filter.ShowSiteFilter = ShowSiteNameColumn;
         filter.IsLiveSite = IsLiveSite;
     }
 }
    private void ugRecycleBin_OnFilterFieldCreated(string columnName, UniGridFilterField filterDefinition)
    {
        filter = filterDefinition.ValueControl as CMSAbstractRecycleBinFilterControl;

        if (filter != null)
        {
            filter.DisplayDateTimeFilter = DisplayDateTimeFilter;

            // If filter is set
            if (filter.FilterIsSet)
            {
                ugRecycleBin.ZeroRowsText = GetString("unigrid.filteredzerorowstext");
            }
            else
            {
                ugRecycleBin.ZeroRowsText = IsSingleSite ? GetString("RecycleBin.NoDocuments") : GetString("RecycleBin.Empty");
            }
        }
    }
    /// <summary>
    /// Ensures correct style for document filter.
    /// </summary>
    protected void gridDocuments_OnFilterFieldCreated(string columnName, UniGridFilterField filter)
    {
        switch (columnName.ToLowerCSafe())
        {
            case "classdisplayname":
            case "documentname":
                if (filter.ValueControl != null)
                {
                    ((TextBox)filter.ValueControl).CssClass = "LongFilterTextBox";
                }
                if (filter.OptionsControl != null)
                {
                    ((DropDownList)filter.OptionsControl).CssClass = "LongDropDownList";
                }

                break;
        }
    }
Пример #21
0
 void gridElem_OnFilterFieldCreated(string columnName, UniGridFilterField filterDefinition)
 {
     var filter = filterDefinition.ValueControl as CMSModules_ContactManagement_Controls_UI_Activity_Filter;
     if (filter != null)
     {
         filter.ShowContactSelector = ShowContactNameColumn;
         filter.ShowSiteFilter = ShowSiteNameColumn;
         filter.ShowIPFilter = ShowIPAddressColumn;
     }
 }
 void gridElem_OnFilterFieldCreated(string columnName, UniGridFilterField filterDefinition)
 {
     filter = filterDefinition.ValueControl as CMSModules_ContactManagement_Controls_UI_Account_Filter;
     if (filter != null)
     {
         filter.NotMerged = true;
         filter.IsLiveSite = IsLiveSite;
         filter.ShowGlobalStatuses = ConfigurationHelper.AuthorizedReadConfiguration(UniSelector.US_GLOBAL_RECORD, false);
     }
 }
    /// <summary>
    /// Add filter field to the filter table.
    /// </summary>
    /// <param name="filter">Filter definition</param>
    /// <param name="columnSourceName">Column source field name</param>
    /// <param name="fieldDisplayName">Field display name</param>
    /// <param name="filterTable">Filter table</param>
    /// <param name="filterOption">Filter option</param>
    /// <param name="filterValue">Filter value</param>
    private void AddFilterField(ColumnFilter filter, string columnSourceName, string fieldDisplayName, Table filterTable, object filterOption, object filterValue)
    {
        string fieldType = filter.Type;
        string fieldPath = filter.Path;
        string filterFormat = filter.Format;
        string fieldSourceName = filter.Source ?? columnSourceName;
        int filterSize = filter.Size;
        Unit filterWidth = filter.Width;

        TableRow tRow = new TableRow();

        TableCell tCellName = new TableCell();
        TableCell tCellOption = new TableCell();
        TableCell tCellValue = new TableCell();

        // Ensure fieldSourceName is JavaScript valid
        fieldSourceName = fieldSourceName.Replace(ALL, "__ALL__");

        // Label
        Label textName = new Label
        {
            Text = String.IsNullOrEmpty(fieldDisplayName) ? "" : fieldDisplayName + ":",
            ID = fieldSourceName + "Name",
            EnableViewState = false
        };

        tCellName.Controls.Add(textName);
        tRow.Cells.Add(tCellName);

        // Filter option
        string option = null;
        if (filterOption != null)
        {
            option = ValidationHelper.GetString(filterOption, null);
        }

        // Filter value
        string value = null;
        if (filterValue != null)
        {
            value = ValidationHelper.GetString(filterValue, null);
        }

        // Filter definition
        UniGridFilterField filterDefinition = new UniGridFilterField();
        filterDefinition.Type = (fieldType != null) ? fieldType.ToLowerCSafe() : "custom";
        filterDefinition.Label = textName;
        filterDefinition.Format = filterFormat;
        filterDefinition.FilterRow = tRow;

        string customPath = null;

        // Set the filter default value
        string defaultValue = filter.DefaultValue;

        // Remember default values of filter field controls for potential UniGrid reset
        string optionFilterFieldValue = null;
        string valueFilterFieldValue = null;

        switch (filterDefinition.Type)
        {
            // Text filter
            case "text":
                {
                    DropDownList textOptionFilterField = new DropDownList();

                    textOptionFilterField.Items.Add(new ListItem("LIKE", "LIKE"));
                    textOptionFilterField.Items.Add(new ListItem("NOT LIKE", "NOT LIKE"));
                    textOptionFilterField.Items.Add(new ListItem("=", "="));
                    textOptionFilterField.Items.Add(new ListItem("<>", "<>"));
                    textOptionFilterField.CssClass = "ContentDropdown";
                    textOptionFilterField.ID = fieldSourceName;

                    // Set the value
                    SetDropdownValue(value, null, textOptionFilterField);
                    optionFilterFieldValue = textOptionFilterField.SelectedValue;

                    LocalizedLabel lblSelect = new LocalizedLabel
                    {
                        EnableViewState = false,
                        Display = false,
                        AssociatedControlID = textOptionFilterField.ID,
                        ResourceString = "general.select"
                    };

                    tCellOption.Controls.Add(lblSelect);
                    tCellOption.Controls.Add(textOptionFilterField);
                    tRow.Cells.Add(tCellOption);

                    // Add text field
                    TextBox textValueFilterField = new TextBox
                    {
                        ID = fieldSourceName + "TextValue",
                        CssClass = "FilterTextBox",
                    };

                    // Set value
                    SetTextboxValue(value, defaultValue, textValueFilterField);
                    valueFilterFieldValue = textValueFilterField.Text;

                    if (filterSize > 0)
                    {
                        textValueFilterField.MaxLength = filterSize;
                    }
                    if (!filterWidth.IsEmpty)
                    {
                        textValueFilterField.Width = filterWidth;
                    }
                    tCellValue.Controls.Add(textValueFilterField);
                    tRow.Cells.Add(tCellValue);
                    textName.AssociatedControlID = textValueFilterField.ID;

                    filterDefinition.OptionsControl = textOptionFilterField;
                    filterDefinition.ValueControl = textValueFilterField;
                }
                break;

            // Boolean filter
            case "bool":
                {
                    DropDownList booleanOptionFilterField = new DropDownList();

                    booleanOptionFilterField.Items.Add(new ListItem(GetString("general.selectall"), ""));
                    booleanOptionFilterField.Items.Add(new ListItem(GetString("general.yes"), "1"));
                    booleanOptionFilterField.Items.Add(new ListItem(GetString("general.no"), "0"));
                    booleanOptionFilterField.CssClass = "ContentDropdown";
                    booleanOptionFilterField.ID = fieldSourceName;
                    textName.AssociatedControlID = booleanOptionFilterField.ID;

                    // Set the value
                    SetDropdownValue(value, defaultValue, booleanOptionFilterField);
                    valueFilterFieldValue = booleanOptionFilterField.SelectedValue;

                    tCellValue.Controls.Add(booleanOptionFilterField);
                    tRow.Cells.Add(tCellValue);

                    filterDefinition.ValueControl = booleanOptionFilterField;
                }
                break;

            // Integer filter
            case "integer":
            case "double":
                {
                    DropDownList numberOptionFilterField = new DropDownList();
                    numberOptionFilterField.Items.Add(new ListItem("=", "="));
                    numberOptionFilterField.Items.Add(new ListItem("<>", "<>"));
                    numberOptionFilterField.Items.Add(new ListItem("<", "<"));
                    numberOptionFilterField.Items.Add(new ListItem(">", ">"));
                    numberOptionFilterField.CssClass = "ContentDropdown";
                    numberOptionFilterField.ID = fieldSourceName;

                    // Set the value
                    SetDropdownValue(value, null, numberOptionFilterField);
                    optionFilterFieldValue = numberOptionFilterField.SelectedValue;

                    LocalizedLabel lblSelect = new LocalizedLabel
                    {
                        EnableViewState = false,
                        Display = false,
                        AssociatedControlID = numberOptionFilterField.ID,
                        ResourceString = "general.select"
                    };

                    // Add filter field
                    tCellOption.Controls.Add(lblSelect);
                    tCellOption.Controls.Add(numberOptionFilterField);
                    tRow.Cells.Add(tCellOption);

                    TextBox numberValueFilterField = new TextBox
                    {
                        ID = fieldSourceName + "NumberValue",
                    };

                    // Set value
                    SetTextboxValue(value, defaultValue, numberValueFilterField);
                    valueFilterFieldValue = numberValueFilterField.Text;

                    if (filterSize > 0)
                    {
                        numberValueFilterField.MaxLength = filterSize;
                    }
                    if (!filterWidth.IsEmpty)
                    {
                        numberValueFilterField.Width = filterWidth;
                    }
                    numberValueFilterField.EnableViewState = false;

                    tCellValue.Controls.Add(numberValueFilterField);
                    tRow.Cells.Add(tCellValue);

                    filterDefinition.OptionsControl = numberOptionFilterField;
                    filterDefinition.ValueControl = numberValueFilterField;
                }
                break;

            case "site":
                {
                    // Site selector
                    customPath = "~/CMSFormControls/Filters/SiteFilter.ascx";
                }
                break;

            case "custom":
                // Load custom path
                {
                    if (String.IsNullOrEmpty(fieldPath))
                    {
                        throw new Exception("[UniGrid.AddFilterField]: Filter field path is not set");
                    }

                    customPath = fieldPath;
                }
                break;

            default:
                // Not supported filter type
                throw new Exception("[UniGrid.AddFilterField]: Filter type '" + filterDefinition.Type + "' is not supported. Supported filter types: integer, double, bool, text, site, custom.");
        }

        // Else if filter path is defined use custom filter
        if (customPath != null)
        {
            customPath = (customPath.StartsWithCSafe("~/") ? customPath : FilterDirectoryPath + customPath.TrimStart('/'));

            // Add to the controls collection
            CMSAbstractBaseFilterControl filterControl = LoadFilterControl(fieldPath, fieldSourceName, value, filterDefinition, customPath);
            if (filterControl != null)
            {
                // Set default value
                if (!String.IsNullOrEmpty(defaultValue))
                {
                    filterControl.SelectedValue = defaultValue;
                }

                tCellValue.Controls.Add(filterControl);
            }

            tCellValue.Attributes["colspan"] = "2";
            tRow.Cells.Add(tCellValue);
        }

        RaiseOnFilterFieldCreated(fieldSourceName, filterDefinition);
        FilterFields[fieldSourceName] = filterDefinition;

        filterTable.Rows.Add(tRow);

        // Store initial filter state for potential UniGrid reset
        if (filterDefinition.OptionsControl != null)
        {
            InitialFilterStateControls.Add(new KeyValuePair<Control, object>(filterDefinition.OptionsControl, optionFilterFieldValue));
        }
        if (filterDefinition.ValueControl != null)
        {
            if (!(filterDefinition.ValueControl is CMSAbstractBaseFilterControl))
            {
                InitialFilterStateControls.Add(new KeyValuePair<Control, object>(filterDefinition.ValueControl, valueFilterFieldValue));
            }
        }
    }