Multi valued custom field editor

2 posts, 0 answers
  1. Charlie
    Charlie avatar
    4 posts
    Member since:
    Jun 2011

    Posted 24 Jun 2011 Link to this post

    I'm attempting to create a custom field editor, and using the RadDropDownFilter example as a guide.  My custom editor however has multiple fields - two text boxes, and two combo boxes.

    When using the example code, on a postback the ArrayList in the SetEditorValues method only contains a single value - not the values entered for all four controls.  The ExtractValues method does seem to be outputting an ArrayList with four elements.

    Any thoughts?  I'm guessing the issue might be that the inherited class - RadFilterDataFieldEditor - doesn't support multiple values?  Should I be deriving from some other class?  Code for the custom editor:

    public class RadFilterRangeValueTypeStrategy : RadFilterDataFieldEditor
            {
                private RadComboBox _combo_ValueType;
                private RadComboBox _combo_Strategy;
     
                private RadTextBox _textMin;
                private RadTextBox _textMax;
     
     
                protected override void CopySettings(RadFilterDataFieldEditor baseEditor)
                {
                    base.CopySettings(baseEditor);
     
                    var editor = baseEditor as RadFilterRangeValueTypeStrategy;
                    if (editor != null)
                    {
                        DataSource_ValueType = editor.DataSource_ValueType;
                        DataTextField_ValueType = editor.DataTextField_ValueType;
                        DataValueField_ValueType = editor.DataValueField_ValueType;
     
                        DataSource_Strategy = editor.DataSource_Strategy;
                        DataTextField_Strategy = editor.DataTextField_Strategy;
                        DataValueField_Strategy = editor.DataValueField_Strategy;
     
                        MinValue = editor.MinValue;
                        MaxValue = editor.MaxValue;
                    }
                }
     
     
                public override System.Collections.ArrayList ExtractValues()
                {
                    ArrayList list = new ArrayList();
     
                    list.Add(_combo_ValueType.SelectedValue);
     
                    list.Add(_combo_Strategy.SelectedValue);
     
                    list.Add(_textMin.Text);
     
                    list.Add(_textMax.Text);
     
                    return list;
     
                }
     
                public override void InitializeEditor(System.Web.UI.Control container)
                {
     
                    Label minLabel = new Label();
                    minLabel.Text = "Min: ";
     
                    container.Controls.Add(minLabel);
     
                    _textMin = new RadTextBox();
                    _textMin.ID = "MinValue";
                    _textMin.Text = MinValue;
                    _textMin.Width = Unit.Pixel(30);
                    container.Controls.Add(_textMin);
     
     
                    Label maxLabel = new Label();
                    maxLabel.Text = "  Max: ";
     
                    container.Controls.Add(maxLabel);
     
                    _textMax = new RadTextBox();
                    _textMax.ID = "MaxValue";
                    _textMax.Text = MaxValue;
                    _textMax.Width = Unit.Pixel(30);
                    container.Controls.Add(_textMax);
     
     
     
                    Label valueTypeLabel = new Label();
                    valueTypeLabel.Text = "  Value Type: ";
     
                    container.Controls.Add(valueTypeLabel);
     
                    _combo_ValueType = new RadComboBox();
                    _combo_ValueType.ID = "ValueTypeCombo";
                    _combo_ValueType.DataTextField = DataTextField_ValueType;
                    _combo_ValueType.DataValueField = DataValueField_ValueType;
                    _combo_ValueType.DataSource = DataSource_ValueType;
                    _combo_ValueType.DataBind();
                    _combo_ValueType.Width = Unit.Pixel(30);
                    container.Controls.Add(_combo_ValueType);
     
     
     
                    Label strategyLabel = new Label();
                    strategyLabel.Text = "  Strategy: ";
     
                    container.Controls.Add(strategyLabel);
     
                    _combo_Strategy = new RadComboBox();
                    _combo_Strategy.ID = "StrategyCombo";
                    _combo_Strategy.DataTextField = DataTextField_Strategy;
                    _combo_Strategy.DataValueField = DataValueField_Strategy;
                    _combo_Strategy.DataSource = DataSource_Strategy;
                    _combo_Strategy.DataBind();
                    _combo_Strategy.Width = Unit.Pixel(40);
                    container.Controls.Add(_combo_Strategy);
     
                   
                }
     
                public override void SetEditorValues(System.Collections.ArrayList values)
                {
                    if (values != null && values.Count > 0)
                    {
                        if (values[0] == null)
                            return;
                        var item = _combo_ValueType.FindItemByValue(values[0].ToString());
                        if (item != null)
                            item.Selected = true;
                    }
     
                    if (values != null && values.Count > 1)
                    {
                        if (values[1] == null)
                            return;
                        var item = _combo_Strategy.FindItemByValue(values[1].ToString());
                        if (item != null)
                            item.Selected = true;
                    }
     
                    if (values != null && values.Count > 2)
                    {
                        if (values[2] == null)
                            return;
     
                        _textMin.Text = values[2].ToString();
                    }
     
                    if (values != null && values.Count > 3)
                    {
                        if (values[3] == null)
                            return;
     
                        _textMax.Text = values[3].ToString();
                    }
                }
     
                public string DataTextField_ValueType
                {
                    get
                    {
                        return (string)ViewState["DataTextField_ValueType"] ?? string.Empty;
                    }
                    set
                    {
                        ViewState["DataTextField_ValueType"] = value;
                    }
                }
     
                public string DataValueField_ValueType
                {
                    get
                    {
                        return (string)ViewState["DataValueField_ValueType"] ?? string.Empty;
                    }
                    set
                    {
                        ViewState["DataValueField_ValueType"] = value;
                    }
                }
     
                public RadFilterDropDownEditorDataSource DataSource_ValueType
                {
                    get
                    {
                        return (RadFilterDropDownEditorDataSource)ViewState["DataSource_ValueType"] ?? new RadFilterDropDownEditorDataSource();
                    }
                    set
                    {
                        ViewState["DataSource_ValueType"] = value;
                    }
                }
     
     
     
                public string DataTextField_Strategy
                {
                    get
                    {
                        return (string)ViewState["DataTextField_Strategy"] ?? string.Empty;
                    }
                    set
                    {
                        ViewState["DataTextField_Strategy"] = value;
                    }
                }
     
                public string DataValueField_Strategy
                {
                    get
                    {
                        return (string)ViewState["DataValueField_Strategy"] ?? string.Empty;
                    }
                    set
                    {
                        ViewState["DataValueField_Strategy"] = value;
                    }
                }
     
                public RadFilterDropDownEditorDataSource DataSource_Strategy
                {
                    get
                    {
                        return (RadFilterDropDownEditorDataSource)ViewState["DataSource_Strategy"] ?? new RadFilterDropDownEditorDataSource();
                    }
                    set
                    {
                        ViewState["DataSource_Strategy"] = value;
                    }
                }
     
     
                public string MinValue
                {
                    get
                    {
                        return (string)ViewState["MinValue"] ?? string.Empty;
                    }
                    set
                    {
                        ViewState["MinValue"] = value;
                    }
                }
     
                public string MaxValue
                {
                    get
                    {
                        return (string)ViewState["MaxValue"] ?? string.Empty;
                    }
                    set
                    {
                        ViewState["MaxValue"] = value;
                    }
                }
     
            }
     
     
     
        }
  2. Mira
    Admin
    Mira avatar
    1124 posts

    Posted 28 Jun 2011 Link to this post

    Hello Charlie,

    RadFilter FilterExpression types are listed in the table in this help topic. Most of them work with only one value and the RadFilterBetweenFilterExpression and RadFilterBetweenFilterExpression work with two values.
    That is way only the first one or two items from the list returned from the ExtractValues() method are used.
    In order to implement the desired functionality, I recommend that you use two or more field editors for generating the desired complex filter expression.

    I hope this helps.

    All the best,
    Mira
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top