CS0029 Cannot implicitly convert type 'Microsoft.AspNetCore.Components.ElementReference' to 'Syncfusion.Blazor.Grids.SfGrid

I have a solution where the data models are all in a separate shared project. 

I have added an SfGrid to an existing Razor page, as shown below. In my razor.cs file, both the grid and that datasource are using the same type (from the shared project). Although the project runs and displays the data correctly, I would like to know how to get rid of the following error?

"CS0029 Cannot implicitly convert type 'Microsoft.AspNetCore.Components.ElementReference' to 'Syncfusion.Blazor.Grids.SfGrid'"

Razor File

Razor.cs File

private SfGrid RideGrid;

protected IEnumerable AllRidersWithDistance { get; set; } = new List();


3 Replies

PS Prathap Senthil Syncfusion Team March 13, 2023 02:30 PM UTC

Hi Simon,

To resolve this issue, you need to ensure that you are correctly referencing the SfGrid component in your code. It's possible that you are passing an ElementReference object where a SfGrid object is expected. If the issue persists, we kindly request that you provide a simple reproducible sample, or if possible try modifying the attached sample to see if the issue can be reproduced there . We appreciate your cooperation and hope to resolve this issue for you as soon as possible.

Regards,
Prathap S



Attachment: BlazorDatagrid_d68f3f4e.zip


SI Simon March 13, 2023 05:52 PM UTC

Thanks for your quick response.

The only difference I could see between your example and mine was the order of the parameters in the SfGrid element.

I changed from 1 to 2 and this solved the problem.  I was not aware that order was relevant

1) <SfGrid  TValue="RiderWithDistanceDTO" @ref="RideGrid" DataSource=@AllRidersWithDistance AllowSorting="true" AllowPaging="true" Height="100vh">

2) <SfGrid DataSource=@AllRidersWithDistance @ref="RideGrid" TValue="RiderWithDistanceDTO" AllowSorting="true" AllowPaging="true" Height="100vh">




PS Prathap Senthil Syncfusion Team March 14, 2023 11:02 AM UTC

Thanks for the update,

Glad to hear that changing the order of the parameters in the SfGrid element solved your problem with Syncfusion Blazor DataGrid. Therefore, it is important to make sure that the order of the parameters in the SfGrid element matches the order of the parameters defined in the component. Kindly refer to the attached documentation for your reference.

Documentation: https://blazor.syncfusion.com/documentation/datagrid/data-binding


Loader.
Up arrow icon