Filter with fieldEditor, witch has fieldName not from Grid column

4 posts, 0 answers
  1. Petras
    Petras avatar
    2 posts
    Member since:
    Dec 2019

    Posted 13 Mar Link to this post

    I am using Filter with Grid. If I set FieldName in the FieldEditors that is not in the Grid column (but from binded table), I get null reference exception after call RadFilter1.FireApplyCommand(). Is it Filter control limitation? If yes, is there work around?


    Stack trace:

       at Telerik.Web.UI.RadFilterDataFieldEditor.CreateEditorFrom(RadFilterDataFieldEditor baseEditor)
       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.RecreateControl()
       at Telerik.Web.UI.RadFilter.ContainerFieldDescriptorsReady(Object sender, RadFilterFildDesciptorsEventArgs e)
       at Telerik.Web.UI.RadGrid.OnFieldDescriptorsReady(RadFilterFildDesciptorsEventArgs e)
       at Telerik.Web.UI.RadGrid.UpdateFilterControl()
       at Telerik.Web.UI.GridTableView.SavePagingData(Boolean useDataSource, GridPagingManager paging)
       at Telerik.Web.UI.GridTableView.CreateControlHierarchy(Boolean useDataSource)
       at Telerik.Web.UI.GridTableView.CreateChildControls(IEnumerable dataSource, Boolean useDataSource)
       at System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data)
       at System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data)
       at System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback)
       at System.Web.UI.WebControls.DataBoundControl.PerformSelect()
       at Telerik.Web.UI.GridTableView.PerformSelect()
       at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()
       at Telerik.Web.UI.GridTableView.DataBind()
       at Telerik.Web.UI.GridTableView.Rebind()
       at Telerik.Web.UI.RadGrid.Telerik.Web.UI.IRadFilterableContainer.ApplyFilterExpressions(RadFilterGroupExpression expressionRoot, Boolean shouldBind)
       at Telerik.Web.UI.RadFilter.HandleApplyCommand()
       at Telerik.Web.UI.RadFilter.FireApplyCommand()

  2. Doncho
    Doncho avatar
    64 posts

    Posted 18 Mar Link to this post

    Hi Petras,

    To be able to give you an accurate answer I would require more information about the way you create the FieldEditors in the code behind.

    It would be helpful if you could share the .aspx page and the code-behind and I will take a look myself.

    Kind regards,
    Progress Telerik

    Get quickly onboarded and successful with UI for ASP.NET AJAX with the Virtual Classroom technical trainings, available to all active customers. Learn More.
  3. Petras
    Petras avatar
    2 posts
    Member since:
    Dec 2019

    Posted 18 Mar in reply to Doncho Link to this post

    Hi Doncho,

    Below I am attaching code sample. If I try to filter on  field "NameAlias" and comment line <telerik:GridBoundColumn DataField="NameAlias" Visible="false" />

    I get error. In uncommented version, no exception is thrown.



    <telerik:RadFilter RenderMode="Lightweight" runat="server" ID="RadFilter1" FilterContainerID="RadGrid1">
            <telerik:RadFilterTextFieldEditor FieldName="NameAlias" DisplayName="Trumpas pav" />

    <telerik:RadGrid RenderMode="Lightweight" runat="server" ID="RadGrid1" AutoGenerateColumns="false"
        AllowCustomPaging="true" AllowPaging="true" AllowSorting="true" EnableLinqExpressions="false"
        AllowFilteringByColumn="true" FilterType="HeaderContext" EnableHeaderContextMenu="true" EnableHeaderContextFilterMenu="true"
        OnNeedDataSource="RadGrid1_NeedDataSource" OnDeleteCommand="RadGrid1_DeleteCommand"  Skin="Telerik">
        <ExportSettings ExportOnlyData="true" HideStructureColumns="true" IgnorePaging="true" FileName="File">
            <Excel Format="Xlsx" AutoFitImages="false" />
        <MasterTableView DataKeyNames="RecId" CommandItemDisplay="Top" InsertItemPageIndexAction="ShowItemOnCurrentPage">
                <telerik:GridBoundColumn DataField="ItemName" MaxLength="250" Groupable="false"
                    CurrentFilterFunction="Contains" AutoPostBackOnFilter="true" />
                <%--<telerik:GridBoundColumn DataField="NameAlias" Visible="false" />--%>

  4. Doncho
    Doncho avatar
    64 posts

    Posted 23 Mar Link to this post

    Hi Petras,

    Thank you for the additional information.

    When RadGrid is used as FilterContainer, filtering can be applied only on the data fields bound to the grid. RadFilter itself has no reference to the DataSource of the grid, so using FilterEditor with FieldName that appears in the RadGrid's data source but is not bound to the grid itself, will cause null reference exception.

    Filtering on a column bound to the RadGrid with Visibile property set to "false" is a working solution.

    If you prefer to filter on DataSource control instead of the Grid, you can check out the Integration with DataSource Controls article.

    Kind regards,
    Progress Telerik

    Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
    Our thoughts here at Progress are with those affected by the outbreak.

Back to Top