RadzenDataGrid shows object name, not value

I am trying to use the RadzenDataGrid to display some data. Using a standard HTML table works perfectly, and I see my table with my data

Successful data displayed

However, when I switch out the HTML table for a RadzenDataGrid, I just see the object name of my data source, rather than the actual data values.

Failed data displayed

Here is the successful code;

@page "/fetchplants"

@using BlazorApp.Data
@using Radzen.Blazor

@inject PlantService PlantService

<h1>Plants List</h1>

@if (_plants == null)
{
    <p><em>Loading...</em></p>
}
else
{
    <table class="table">
        <thead>
            <tr>
                <th>Plant Id</th>
                <th>Plant Short</th>
                <th>Plant Name</th>
                <th>Business Unit</th>
                <th>Depot Id</th>
                <th>Depot Short</th>
                <th>Depot Name</th>
            </tr>
        </thead>
        <tbody>
            @foreach (Plant p in _plants)
            {
                <tr>
                    <td>@p.plantId</td>
                    <td>@p.plantShort</td>
                    <td>@p.plantName</td>
                    <td>@p.businessUnit</td>
                    <td>@p.depotId</td>
                    <td>@p.depotShort</td>
                    <td>@p.depotName</td>
                </tr>
            }
        </tbody>
    </table>
}

@code {
    private IEnumerable<Plant> _plants;
    private int _count;

    protected override Task OnInitializedAsync()
    {
        List<Plant> plants = PlantService.GetPlants();
        _plants = plants;
        _count = plants.Count;

        return base.OnInitializedAsync();
    }
}

And here is the code that is giving me the issue (I have only included a couple of columns as it's not working);

@page "/fetchplants"

@using BlazorApp.Data
@using Radzen.Blazor


@inject PlantService PlantService

<h1>Plants List</h1>

@if (_plants == null)
{
    <p><em>Loading...</em></p>
}
else
{
    <RadzenDataGrid Count="_count" Data="@_plants" TItem="Plant">
        <Columns>
            <RadzenDataGridColumn TItem="Plant" Property="plantID" Title="Plant ID"></RadzenDataGridColumn>
            <RadzenDataGridColumn TItem="Plant" Property="plantName" Title="Plant Name"></RadzenDataGridColumn>
        </Columns>
    </RadzenDataGrid>
}

@code {
    private IEnumerable<Plant> _plants;
    private int _count;

    protected override Task OnInitializedAsync()
    {
        List<Plant> plants = PlantService.GetPlants();
        _plants = plants;
        _count = plants.Count;

        return base.OnInitializedAsync();
    }
}

So I know my service that returns the data is good as it works with the HTML table. I know my Plant class is good for the same reason. Every example I have looked at looks identical to my code.

I have been Googling for hours and I can't find anything remotely helpful, so it must be something very stupid that I am doing wrong as nobody else seems to have had this problem!

You have fields instead properties in my opinion.

1 Like

Hi Vladimir

You are absolutely correct, that was my issue! And thank you for responding so quickly, it is greatly appreciated.