We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

I want to display data from two classes in a table

Hello Dear Syncfusion-Team,

i have a problem to load Data in my DataGrid. When i try to load a virtual property. I have two classes Category and CategoryBody. In CategoryBody i have a virtual Porperty Category. I want to access the properties of the class Category and output them in my table. Here is my Code:

Category Class: I want to access the Description property

InkedSyncfusionDataGrid1.jpg


CategoryBody class with the virtual Property Category:

InkedSyncFusionCategoryBody.jpg


Razor Page with DazaGrid: I try this way to access the Description property from Category class

InkedCategoriesGridCode.jpg


Output: The Description Column is Empty

InkedTable.jpg


3 Replies 1 reply marked as answer

MS Monisha Saravanan Syncfusion Team December 19, 2022 11:39 AM UTC


Hi Artur,


Greetings from Syncfusion support.


We suggest you to use the dot(.) operator in the column field for complex columns by using the below way. Kindly check the below attached code snippet and documentation for your reference.


 

<SfGrid DataSource="@Employees" Height="315">

    <GridColumns>

        <GridColumn Field="Category.Description" HeaderText="Last Name"Width="130"></GridColumn>

    </GridColumns>

</SfGrid>

 

@code{

 

    public class EmployeeData

    {

       

        public virtual Category Category { get; set; }

    }

 

    public class Category

    {

        public string Description { get; set; }

       

    }

}


If you need to use nameof operator then kindly check the notes section from the below documentation.


Reference: https://blazor.syncfusion.com/documentation/datagrid/columns#complex-data-binding


Please let us know if you have any queries.


Regards,

Monisha

If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.



Marked as answer

AZ Artur Zigel December 21, 2022 08:39 AM UTC

Thank you for the great support



MS Monisha Saravanan Syncfusion Team December 22, 2022 04:37 AM UTC

Hi Artur,


Welcome. Kindly get back to us if you have further queries. As always we will be happy to assist you.


Loader.
Live Chat Icon For mobile
Up arrow icon