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

Custom RadFilterDataFieldEditor issue

3 Answers 129 Views
Filter
This is a migrated thread and some comments may be shown as answers.
Felipe
Top achievements
Rank 1
Felipe asked on 28 Mar 2011, 11:39 PM
Hello,

I am trying to use a custom radfilter datafield editor.  I am not binding the radfilter directly to anything.... i am merely using it to provide the user an interface to create an advanced grouped query - and then using it to get the strongly typed where condition.

the field I am having an issue with is technically a numerical field editor - although the fields they are referring to in the database are bit fields.

as a result, i am trying to only allow the user to choose between the values 0 and 1 through a dropdown box (with displayed values of "true" and "false" instead.

this seems to work.... once.  it will add the field editor once, but when i try to add another expression item, it runs into an error.

it looks like i am not passing on some editor variable from the base object... and possibly missing an override, but i am not sure.

the code for the editor is below:

public class RadFilterBooleanDropDownEditor : RadFilterDataFieldEditor
    {
        protected override void CopySettings(RadFilterDataFieldEditor baseEditor)
        {
            base.CopySettings(baseEditor);
            var editor = baseEditor as RadFilterBooleanDropDownEditor;
            if (editor != null)
            {
                //DataSourceID = editor.DataSourceID;
                //DataTextField = editor.DataTextField;
                //DataValueField = editor.DataValueField;
            }
 
        }
         
        public override System.Collections.ArrayList ExtractValues()
        {
            ArrayList list = new ArrayList();
            list.Add(int.Parse(_combo.SelectedValue));
            return list;
        }
 
        public override void InitializeEditor(System.Web.UI.Control container)
        {
            _combo = new RadComboBox();
            _combo.ID = "MyCombo";
            _combo.Width = System.Web.UI.WebControls.Unit.Pixel(48);
 
            _combo.Items.Add(new RadComboBoxItem("True","1"));
            _combo.Items.Add(new RadComboBoxItem("False","0"));
 
            //container.Controls[1].Visible = false;
 
            container.Controls.Add(_combo);
        }
 
 
        public override void SetEditorValues(System.Collections.ArrayList values)
        {
            if (values != null && values.Count > 0)
            {
                if (values[0] == null)
                    return;
                var item = _combo.FindItemByValue(values[0].ToString());
                if (item != null)
                    item.Selected = true;
            }
        }
 
        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 string DataSourceID
        {
            get
            {
                return (string)ViewState["DataSourceID"] ?? string.Empty;
            }
            set
            {
                ViewState["DataSourceID"] = value;
            }
        }
 
        private RadComboBox _combo;
    }


and the error i get is as follows:

Object reference not set to an instance of an object.
 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
 
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
 
Source Error:
 
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
 
Stack Trace:
 
 
[NullReferenceException: Object reference not set to an instance of an object.]
   Telerik.Web.UI.RadFilterDataFieldEditor.CreateEditorFrom(RadFilterDataFieldEditor baseEditor) +9
   Telerik.Web.UI.RadFilterSingleExpressionItem.SetupFunctionInterface(Control container) +55
   Telerik.Web.UI.RadFilterExpressionItem.CreateFunctionalInterface() +89
   Telerik.Web.UI.RadFilterExpressionItem.InitializeItem() +24
   Telerik.Web.UI.RadFilter.CreateFilterItems() +284
   Telerik.Web.UI.RadFilter.CreateControlHierarchy() +34
   Telerik.Web.UI.RadFilter.CreateChildControls() +90
   System.Web.UI.Control.EnsureChildControls() +102
   System.Web.UI.Control.FindControl(String id, Int32 pathOffset) +20
   System.Web.UI.Control.FindControl(String id, Int32 pathOffset) +365
   System.Web.UI.Control.FindControl(String id, Int32 pathOffset) +365
   System.Web.UI.Control.FindControl(String id, Int32 pathOffset) +365
   System.Web.UI.Control.FindControl(String id, Int32 pathOffset) +365
   System.Web.UI.Control.FindControl(String id, Int32 pathOffset) +365
   System.Web.UI.Control.FindControl(String id, Int32 pathOffset) +365
   System.Web.UI.Page.FindControl(String id) +38
   System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean fBeforeLoad) +287
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +878


any help with troubleshooting this issue would be MUCH appreciated.  thanks!

3 Answers, 1 is accepted

Sort by
0
Mira
Telerik team
answered on 31 Mar 2011, 03:39 PM
Hello Leland,

I have followed your scenario and prepared a sample project for you demonstrating how the desired functionality can be implemented. You can find it attached to this post.

Please take a look at it and let me know whether it helps.

All the best,
Mira
the Telerik team
0
Felipe
Top achievements
Rank 1
answered on 31 Mar 2011, 04:24 PM
Hello Mira,

Thank you very much for your work...

I am still having the same issue though.  The first expression that I add works fine.  Then when I try to apply a second one, i get the following error:

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
 
Source Error:
 
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
 
Stack Trace:
 
 
[NullReferenceException: Object reference not set to an instance of an object.]
   Telerik.Web.UI.RadFilterDataFieldEditor.CreateEditorFrom(RadFilterDataFieldEditor baseEditor) +31
   Telerik.Web.UI.RadFilterDataFieldEditorCollection.RetrieveEditorForFieldName(String fieldName) +60
   Telerik.Web.UI.RadFilterSingleExpressionItem.SetupFunctionInterface(Control container) +101
   Telerik.Web.UI.RadFilterExpressionItem.CreateFunctionalInterface() +124
   Telerik.Web.UI.RadFilterExpressionItem.InitializeItem() +41
   Telerik.Web.UI.RadFilter.CreateFilterItems() +385
   Telerik.Web.UI.RadFilter.CreateControlHierarchy() +58
   Telerik.Web.UI.RadFilter.CreateChildControls() +134
   System.Web.UI.Control.EnsureChildControls() +102
   System.Web.UI.Control.FindControl(String id, Int32 pathOffset) +20
   System.Web.UI.Control.FindControl(String id, Int32 pathOffset) +365
   System.Web.UI.Control.FindControl(String id, Int32 pathOffset) +365
   System.Web.UI.Control.FindControl(String id, Int32 pathOffset) +365
   System.Web.UI.Control.FindControl(String id, Int32 pathOffset) +365
   System.Web.UI.Control.FindControl(String id, Int32 pathOffset) +365
   System.Web.UI.Control.FindControl(String id, Int32 pathOffset) +365
   System.Web.UI.Page.FindControl(String id) +38
   System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean fBeforeLoad) +287
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +878

I am beginning to think it is not the editor... but the way I am creating the editor from code-behind?

here is what i did to try and use your code:

void CreateFieldEditor(string fld)
{
    RadFilterDropDownEditor editor = new RadFilterDropDownEditor();
    editor.DisplayName = fld;
    editor.DataType = typeof(int);
    editor.FieldName = fld;
 
    editor.DataSource = BooleanDataSource();
 
    RadFilter1.FieldEditors.Add(editor);
 
}
 
private static List<DocumentSearch.results.AccountCollection> BooleanDataSource()
{
    List<DocumentSearch.results.AccountCollection> _list = new List<DocumentSearch.results.AccountCollection>();
 
    foreach (int i in Enum.GetValues(typeof(Test)))
    {
        _list.Add(new DocumentSearch.results.AccountCollection(Enum.GetName(typeof(Test), i), i.ToString()));
    }
 
    return _list;
 
}

and I call "CreateFieldEditor(<field name>)" on Page_Load BOTH during postbacks and not....

this should work, right?

also:  I am not adding the <custom:RadFilterDropDownEditor /> tag in the markup....

i will try and see if either of these two things is causing the problems.... if you have any ideas I would sure appreciate it - thanks.











0
Mira
Telerik team
answered on 06 Apr 2011, 07:49 AM
Hello Leland,

I have modified the sample project to add the field editor on button click. You can find the updated version attached to this post.

I hope it helps.

Greetings,
Mira
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Filter
Asked by
Felipe
Top achievements
Rank 1
Answers by
Mira
Telerik team
Felipe
Top achievements
Rank 1
Share this question
or