This is a migrated thread and some comments may be shown as answers.

Throw exception while switch to another dropdown menu expression in RadFilter

2 Answers 30 Views
Filter
This is a migrated thread and some comments may be shown as answers.
Jin
Top achievements
Rank 1
Jin asked on 06 Sep 2012, 07:41 AM
I run the attached sample and add one expression, then I click the dropdown menu item to switch to select another item, it will throw exception. I cannot find the root cause.

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            DataTable dt = new DataTable();


            dt.Columns.Add("AA");
            dt.Columns.Add("BB");


            for (int i = 0; i < 10; i++)
            {
                DataRow row = dt.NewRow();
                row["AA"] = "AA" + i.ToString();
                row["BB"] = "BB" + i.ToString();


                dt.Rows.Add(row);
            }


            for (int i = 0; i < 10; i++)
            {
                RadFilterDropDownEditor dropDownFieldEditor = new RadFilterDropDownEditor();
                RadFilter.FieldEditors.Add(dropDownFieldEditor);
                dropDownFieldEditor.DataTextField = "AA";
                //dropDownFieldEditor.DataValueField = "BB";
                dropDownFieldEditor.DataSource = dt;
                dropDownFieldEditor.FieldName = "PV Field:[" + dt.Rows[i]["BB"].ToString() + "]";


                //RadFilterTextFieldEditor textFieldEditor = new RadFilterTextFieldEditor();
                //RadFilter.FieldEditors.Add(textFieldEditor);
                //textFieldEditor.FieldName = "Code Field:[" + dt.Rows[i]["AA"].ToString() + "]";
            }
        }
    }


    protected void RadFilter_FieldEditorCreating(object sender, RadFilterFieldEditorCreatingEventArgs e)
    {
        if (e.EditorType == "RadFilterDropDownEditor")
        {
            e.Editor = new RadFilterDropDownEditor();
        }
    }


    protected void RadButton1_Click(object sender, EventArgs e)
    {
        


    }


    public class RadFilterDropDownEditor : RadFilterDataFieldEditor
    {
        private RadComboBox _combo;


        protected override void CopySettings(RadFilterDataFieldEditor baseEditor)
        {
            base.CopySettings(baseEditor);
            var editor = baseEditor as RadFilterDropDownEditor;
            if (editor != null)
            {
                DataSource = editor.DataSource;
                DataTextField = editor.DataTextField;
                DataValueField = editor.DataValueField;
            }
        }


        public override System.Collections.ArrayList ExtractValues()
        {
            ArrayList list = new ArrayList();
            list.Add(_combo.Text);
            return list;
        }


        public override void InitializeEditor(System.Web.UI.Control container)
        {
            _combo = new RadComboBox();
            _combo.ID = "RadComboBoxField";
            _combo.DataTextField = DataTextField;            
            _combo.DataSource = DataSource;
            _combo.DataBind();
            container.Controls.Add(_combo);
        }


        public override void SetEditorValues(System.Collections.ArrayList values)
        {
            if (values != null && values.Count > 0)
            {
                if (values[0] == null) return;


                _combo.Text = values[0].ToString();
            }
        }




        public string DataTextField
        {
            get
            {
                return (string)ViewState["DataTextField"] ?? string.Empty;
            }
            set
            {
                ViewState["DataTextField"] = value;
            }
        }
        public string DataValueField
        {
            get
            {
                return (string)ViewState["DataValueField"] ?? string.Empty;
            }
            set
            {
                ViewState["DataValueField"] = value;
            }
        }
        public DataTable DataSource
        {
            get
            {
                return (DataTable)ViewState["DataSource"] ?? new DataTable();
            }
            set
            {
                ViewState["DataSource"] = value;
            }
        }
    }
}

2 Answers, 1 is accepted

Sort by
0
Jin
Top achievements
Rank 1
answered on 07 Sep 2012, 01:51 PM
Could anybody help to check it?
0
Tsvetina
Telerik team
answered on 11 Sep 2012, 04:08 PM
Hi Jin,

The problem is caused by the ":" char that you use in the FieldName. I removed it and the field editors started working correctly on my side.

Regards,
Tsvetina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Filter
Asked by
Jin
Top achievements
Rank 1
Answers by
Jin
Top achievements
Rank 1
Tsvetina
Telerik team
Share this question
or