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

Can't call rebind when using aggregate

4 Answers 67 Views
Grid
This is a migrated thread and some comments may be shown as answers.
William
Top achievements
Rank 1
William asked on 30 Oct 2018, 08:53 PM

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

Sort by
0
Attila Antal
Telerik team
answered on 01 Nov 2018, 08:14 PM
Hi Villiam,

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.

Kind regards,
Attila Antal
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
William
Top achievements
Rank 1
answered on 02 Nov 2018, 04:53 PM

Hi Attila,

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:

Protected Sub RadGrid1_NeedDataSource(sender As Object, e As Telerik.Web.UI.GridNeedDataSourceEventArgs)
    Dim dt As DataTable = FastSQL.SelectQuery(myDataBase, mySelectionString).Tables(0) 'This is a custom class and function we use
    TryCast(RadGrid1, RadGrid).DataSource = dt
End Sub
 
Protected Sub btn_Filter_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_Filter.Click
    RadGrid1.Rebind()
End Sub
 
Sub SortCommand()
    rptperfdetail.Rebind()
End Sub

 

and in the aspx:

<telerik:RadGrid RenderMode="Lightweight" runat="server" ID="rptperfdetail" AllowSorting="true" OnNeedDataSource="rptperfdetail_NeedDataSource" ClientSettings-Scrolling-ScrollHeight="500" AllowFilteringByColumn="true" ShowFooter="true" ClientSettings-Scrolling-AllowScroll="true" ClientSettings-Scrolling-UseStaticHeaders="true" OnSortCommand="SortCommand" EnableEmbeddedSkins="False" >
    <ItemStyle BackColor="#E2E4FF" Font-Size="10" />
    <AlternatingItemStyle Font-Size="10" />
    <HeaderStyle CssClass="CustomHeader" HorizontalAlign="Center" Font-Size="11" />
</telerik:RadGrid>

 

Thank you,

William

0
William
Top achievements
Rank 1
answered on 02 Nov 2018, 05:07 PM

I forgot to add the part that was using aggregate

<MasterTableView AutoGenerateColumns="false" TableLayout="Fixed">
    <Columns>
        <telerik:GridBoundColumn DataField="User" DataType="System.String" SortExpression="User" HeaderButtonType="TextButton" HeaderStyle-Width="18%" HeaderText="User" AutoPostBackOnFilter="true"></telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="Portal" DataType="System.String" SortExpression="Portal" HeaderButtonType="TextButton" HeaderStyle-Width="17%" ItemStyle-Font-Size="10" HeaderText="Portal" AutoPostBackOnFilter="true"></telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="Date" DataType="System.String" SortExpression="Date" HeaderButtonType="TextButton" HeaderStyle-Width="8%" HeaderText="Date" AutoPostBackOnFilter="true"></telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="Time" DataType="System.String" SortExpression="Time" HeaderButtonType="TextButton" HeaderStyle-Width="8%" HeaderText="Time"></telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="Portal Load Seconds" DataType="System.Int32" SortExpression="Portal Load Seconds" HeaderButtonType="TextButton" HeaderStyle-Width="14%" HeaderText="Portal Load Seconds" AutoPostBackOnFilter="true" Aggregate="Sum" FooterAggregateFormatString="Total Seconds: {0}"></telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="Path and Query String" DataType="System.String" SortExpression="Path and Query String" HeaderButtonType="TextButton" HeaderStyle-Width="35%" HeaderText="Path and Query String" AutoPostBackOnFilter="true"></telerik:GridBoundColumn>
    </Columns>
    <EditFormSettings>
        <EditColumn CancelImageUrl="Cancel.gif" InsertImageUrl="Update.gif" UpdateImageUrl="Update.gif">
        </EditColumn>
    </EditFormSettings>
</MasterTableView>

 

 

0
Attila Antal
Telerik team
answered on 05 Nov 2018, 04:32 PM
Hi William,

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.

Kind regards,
Attila Antal
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
William
Top achievements
Rank 1
Answers by
Attila Antal
Telerik team
William
Top achievements
Rank 1
Share this question
or