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

Adding FieldEditors programmatically

3 Answers 238 Views
Filter
This is a migrated thread and some comments may be shown as answers.
apb
Top achievements
Rank 1
apb asked on 25 Apr 2010, 03:55 AM
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

3 Answers, 1 is accepted

Sort by
0
apb
Top achievements
Rank 1
answered on 26 Apr 2010, 03:56 PM
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
 
0
Nikolay Rusev
Telerik team
answered on 29 Apr 2010, 08:35 AM
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.
0
João
Top achievements
Rank 1
answered on 17 May 2011, 03:28 PM
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
Tags
Filter
Asked by
apb
Top achievements
Rank 1
Answers by
apb
Top achievements
Rank 1
Nikolay Rusev
Telerik team
João
Top achievements
Rank 1
Share this question
or