Is it possible to use switch case and set the DataSource with same structure to Blazor DataGrid?

Answer:

Yes. You can set the grid datasource using conditional operator and also using switch case. Please refer the below code snippet and the sample for your reference.



Option: 1

<SfGrid DataSource="@(option == 1 ? Orders1 : Orders2)" AllowPaging="true">

..

..

SfGrid>


Option: 2

<SfGrid DataSource="@SetDataSourceByUsingSwitch()" AllowPaging="true">

..

..

SfGrid>

@code{

Private List SetDataSourceByUsingSwitch(){

//use switch case and return datasource

return data;

}

}




Loader.
Up arrow icon