Throw exception while switch to another dropdown menu expression in RadFilter

3 posts, 0 answers
  1. Jin
    Jin avatar
    80 posts
    Member since:
    Jun 2012

    Posted 06 Sep 2012 Link to this post

    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. Jin
    Jin avatar
    80 posts
    Member since:
    Jun 2012

    Posted 07 Sep 2012 Link to this post

    Could anybody help to check it?
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Tsvetina
    Admin
    Tsvetina avatar
    1874 posts

    Posted 11 Sep 2012 Link to this post

    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.
Back to Top