I'm using advanced data binding and the needdatasource event, but when I try to call rebind I get an exception of type 'System.Reflection.TargetInvocationException'
Is there a better way to get needdatasource to call again and update the radgrid?
4 Answers, 1 is accepted
Generally this error appears when calling the Rebind() method in the NeedDataSource event handler. If that is the case, please ensure that Rebind() method is not called in that event. It is also described in the Advanced Data-binding (Using NeedDataSource Event) article. "Important: You should never call the Rebind () method in a NeedDataSource event handler.You should never call DataBind () as well when using advanced data binding through NeedDataSource . For Microsoft GridView -like data binding, see Simple Data-binding."
Eventually, if you could share the markup and code behind related to the grid we would gladly take a look.
Thanks for the reply. I am calling rebind in other functions to trip the NeedDataSource event, but not actually in the sub itself. I'm using the following code:
and in the aspx:
I forgot to add the part that was using aggregate
Thank you for the additional information.
For any kind of troubleshooting, I suggest turning AJAX off temporarily, in case it's enabled. Thus, you will get more descriptive errors. (see Get more descriptive errors by disabling AJAX article for more).
The code you have shared is working if I bind a dummy DataSource to the grid using DataTables. I am wondering what is happening within the FastSQL.SelectQuery() method. Is this making a select query to an SQL database? If so, can you please run the query manually without using RadGrid and see if that works? I have a feeling that the keywords used in the DataField of some columns contain illegal words (SQL preserved) such as Path, AND. See Reserved Keywords (Transact-SQL) for more.
Also, you may want to double check and ensure that the Spaces in the column names (DataField names) are handled accordingly. Here is a StackOverflow article addressing this concern: How do you deal with blank spaces in column names in SQL Server?
Attached you can find a sample project I've used to test that includes the code snippets provided by you and the grid is working as expected.