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

FireCommandEvent fires NullReferenceException

2 Answers 91 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Yazid
Top achievements
Rank 1
Yazid asked on 15 Aug 2016, 08:57 PM

Hi,

i try to perform filter operation programmatically. So i created an asp button and attached a server side click event handler. The filter operation should be fired in the event handler:

 protected void Filter_Click(object sender, EventArgs e)
 {
            RadGrid grd = grid;
            grid.MasterTableView.FilterExpression = "([Capture] LIKE 'Kind%')"; // Capture is the id and unique name of a GridBoundColumn
            GridColumn column = grid.MasterTableView.GetColumnSafe("Capture");
            column.CurrentFilterFunction = GridKnownFunction.Contains;
            column.CurrentFilterValue = "Kind";
            grd.EnableLinqExpressions = false;
            GridDataItem item = (grid.MasterTableView.GetItems(GridItemType.Item)[2] as GridDataItem);
            item.FireCommandEvent("Filter", new System.Web.UI.Pair("Kind", "Capture")); // exception is being fired at this line
            grid.Rebind();
}

 

This code causes an exception:

 

An exception of type 'System.NullReferenceException' occurred in Telerik.Web.UI.dll but was not handled in user code


   at Telerik.Web.UI.GridColumn.RefreshCurrentFilterValue(GridFilteringItem filteringItem, String functionName)
   at Telerik.Web.UI.GridFilterCommandEventArgs.ExecuteCommand(Object source)
   at Telerik.Web.UI.RadGrid.OnBubbleEvent(Object source, EventArgs e)
   at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
   at Telerik.Web.UI.GridItem.OnBubbleEvent(Object source, EventArgs e)
   at Lusd.Presentation.LusdApplication.UserControls.Schule.InstitutionsListeControl.Filter_Click(Object sender, EventArgs e) in C:\TFS\ZeGOV\LUSD\Client\development\standard\Presentation\Presentation.LusdApplication\UserControls\Schule\InstitutionsListeControl.ascx.cs:line 429
   at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
   at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

 

How can I get it fixed?

 

Thanks in advance

2 Answers, 1 is accepted

Sort by
0
Accepted
Viktor Tachev
Telerik team
answered on 16 Aug 2016, 12:38 PM
Hello Yazid,

Please try to use the approach described in the article below in order to filter the RadGrid from an external button. Give the approach a try and see how it works for you.




Regards,
Viktor Tachev
Telerik by Progress
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
Yazid
Top achievements
Rank 1
answered on 16 Aug 2016, 01:31 PM

Thank you very much.

I found also another solution:

protected void Filter_Click(object sender, EventArgs e)
        {

            grid.MasterTableView.FilterExpression = "([Institution] LIKE \'Hasen%\')";
            GridColumn column = grid.MasterTableView.GetColumnSafe("Institution");
            column.CurrentFilterFunction = GridKnownFunction.Contains;
            column.CurrentFilterValue = "Hasen";
            grid.EnableLinqExpressions = false;
            GridFilteringItem filterItem = grid.MasterTableView.GetItems(GridItemType.FilteringItem)[0] as GridFilteringItem;
            filterItem.FireCommandEvent("Filter", new System.Web.UI.Pair("Contains", "Capture"));
        }

Tags
Grid
Asked by
Yazid
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Yazid
Top achievements
Rank 1
Share this question
or