Adding FieldEditors programmatically

4 posts, 0 answers
  1. apb
    apb avatar
    46 posts
    Member since:
    Nov 2008

    Posted 24 Apr 2010 Link to this post

    Hi,

    I'm trying to set up a rad filter from code.

    This works as expected:
    <telerik:RadFilter ID="RadFilter1" runat="server">  
       <FieldEditors> 
           <telerik:RadFilterTextFieldEditor DataType="System.String" FieldName="MyColumn" /> 
       </FieldEditors> 
    </telerik:RadFilter> 
     

    This doesn't:
    <telerik:RadFilter ID="RadFilter1" runat="server">  
    </telerik:RadFilter> 
     
    protected void Page_Load(object sender, EventArgs e)  
    {  
        RadFilterTextFieldEditor editor = new RadFilterTextFieldEditor();  
        editor.FieldName = "MyColumn";  
        editor.DataType = typeof(System.String);  
        RadFilter1.FieldEditors.Add(editor);  
    }  
     

    When configured programatically, I'm getting the following error as soon as I try to add an expresion (via the UI when the page is running):
    Exception of type 'System.Web.HttpUnhandledException' was thrown. 
     
    ==> Parameter cannot be null or empty.  
    Parameter name: fieldName    
    Stack Traces  
    Source: System.Web  
    at System.Web.UI.Page.HandleError(Exception e)  
    at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)  
    at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)  
    at System.Web.UI.Page.ProcessRequest()  
    at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)  
    at System.Web.UI.Page.ProcessRequest(HttpContext context)  
    at ASP.junk_filters_aspx.ProcessRequest(HttpContext context) in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\bit9.console.web.ui\f02bb933\1bce73bb\App_Web_filters.aspx.83447962.uwhliv7r.0.cs:line 0  
    at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()  
    at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)  
     
    ==> Source: Telerik.Web.UI  
    at Telerik.Web.UI.RadFilterDataFieldEditorCollection.RetrieveEditorForFieldName(String fieldName)  
    at Telerik.Web.UI.RadFilterSingleExpressionItem.SetupFunctionInterface(Control container)  
    at Telerik.Web.UI.RadFilterExpressionItem.CreateFunctionalInterface()  
    at Telerik.Web.UI.RadFilterExpressionItem.InitializeItem()  
    at Telerik.Web.UI.RadFilter.CreateFilterItems()  
    at Telerik.Web.UI.RadFilter.CreateControlHierarchy()  
    at Telerik.Web.UI.RadFilter.CreateChildControls()  
    at System.Web.UI.Control.EnsureChildControls()  
    at Telerik.Web.UI.RadFilter.EnsureItemsCreated()  
    at Telerik.Web.UI.RadFilter.RecreateControl()  
    at Telerik.Web.UI.RadFilter.AddChildExpression(RadFilterGroupExpressionItem groupItem, Boolean isGroup)  
    at Telerik.Web.UI.RadFilterCommandEventArgs.ExecuteCommand(Object source)  
    at Telerik.Web.UI.RadFilter.OnBubbleEvent(Object source, EventArgs args)  
    at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)  
    at Telerik.Web.UI.RadFilterExpressionItem.OnBubbleEvent(Object source, EventArgs args)  
    at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)  
    at System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e)  
    at System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument)  
    at System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)  
    at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)  
    at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)  
    at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)  

    Any suggestions?  Doing this declaratively is not an option for me and I will not have a grid or other "FilterContainer" available.

    -Al
  2. apb
    apb avatar
    46 posts
    Member since:
    Nov 2008

    Posted 26 Apr 2010 Link to this post

    UPDATE:

    I figured out how to get them to appear. If loaded in the Page_ or RadFilter_Init, they appear, but they need to be re-added on each postback and do not appear at all if added later in the page life cycle (for example, in Load).

    I really think this control has huge potential, but would be MUCH more useful if the FieldEditors collection were persisted in ViewState as the expressions are (in a way -- XML, for instance -- that would not trigger viewstate errors if a different fieldset were swapped in). For instance, I am building a query interface that has a dropdown list from which the user can select a view, build a filter, select some columns, and then use the resulting definition to drive grids, charts, etc. Doing this in Init requires jumping through a number of hoops when the user changes the view.

    -Al
     
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2285 posts

    Posted 29 Apr 2010 Link to this post

    Hello Al,

    If you have your RadFilter declarative the options to create its field programmatically are as follow:
    /on load/
    01.protected void Page_Load(object sender, EventArgs e)
    02.    {
    03.        RadFilterTextFieldEditor editor = new RadFilterTextFieldEditor();
    04.        RadFilter1.FieldEditors.Add(editor);
    05.        if (!IsPostBack)
    06.        {
    07.            editor.FieldName = "Field2";
    08.            editor.DataType = typeof(int);
    09.        }
    10.    }


    /on init/
    01.protected override void OnInit(EventArgs e)
    02.    {
    03.        base.OnInit(e);
    04.  
    05.        RadFilterTextFieldEditor editor = new RadFilterTextFieldEditor();
    06.        editor.FieldName = "Field1";
    07.        editor.DataType = typeof(int);
    08.        RadFilter1.FieldEditors.Add(editor);       
    09.}


    All the best,
    Nikolay
    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.
  5. João
    João avatar
    1 posts
    Member since:
    Jul 2010

    Posted 17 May 2011 Link to this post

    Hello, i am having a issue:

    i am adding the field editors to the rad filter programatically, but after selecting the field in the expression it does not change.

    My codebehind:

    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
     
        LoadPlanningRulesOptions();
    }
     
    private void LoadPlanningRulesOptions()
    {
        var options = BusinessProxy.GetPlanningRuleOptions();
     
        foreach (var option in options)
        {
            switch (option.OptionType)
            {
                case PlanningRulesOptionType.Bool:
                    radFilterRuleDefinition.FieldEditors.Add(new RadFilterBooleanFieldEditor
                    {
                        DisplayName = option.Name,
                        FieldName = option.Id.ToString()
                    });
                    break;
                case PlanningRulesOptionType.DateTime:
                    radFilterRuleDefinition.FieldEditors.Add(new RadFilterDateFieldEditor
                    {
                        DisplayName = option.Name,
                        FieldName = option.Id.ToString()
                    });
                    break;
                case PlanningRulesOptionType.Int:
                    radFilterRuleDefinition.FieldEditors.Add(new RadFilterTextFieldEditor
                    {
                        DisplayName = option.Name,
                        FieldName = option.Id.ToString()
                    });
                    break;
                case PlanningRulesOptionType.Text:
                    radFilterRuleDefinition.FieldEditors.Add(new RadFilterTextFieldEditor
                    {
                        DisplayName = option.Name,
                        FieldName = option.Id.ToString()
                    });
                    break;
            }
        }
    }

    My html:

    <telerik:RadFilter  runat="server" ID="radFilterRuleDefinition" ShowApplyButton="False"></telerik:RadFilter>

    Can you explain me what am i doing wrong?

    Thank you
Back to Top