Dhanya Nithin

Dhanya Nithin

  • NA
  • 409
  • 484

DataGrid Render using dynamic column binding & data binding

Feb 21 2024 10:52 AM

I have list of columns for grid specified in a table 'Controls' containing the column_name & column_caption and a SRNO with some other extra details which is not necessary here.

public IEnumerable<ControlSettings> datagrid { get; set; } --> this contains the list of rows from above table.

List<Dictionary<string, object>> gridData { get; set; } = new List<Dictionary<string, object>>();  --> this contains data for the grid where dictionary key is set to be column_name from the above ControlSettings class.

 <Blazorise.DataGrid.DataGrid Data="@gridData" TItem="Dictionary<string, object>">
    <DataGridColumns>
        @foreach (var column in datagrid)
        {
            <DataGridColumn TItem="Dictionary<string, object>" Field="@column.COLUMN_NAME" Caption="@column.COLUMN_CAPTION" />
        }
    </DataGridColumns>
</Blazorise.DataGrid.DataGrid>   

This is the code i used for displaying the grid. But the grid is not getting displayed & getting error.

Error is : ArgumentException: Cannot detect the member of System.Collections.Generic.Dictionary`2[System.String,System.Object] (Parameter 'LOC')

Note: LOC is one of the column_name

The issue might be because of dictionary usage.

please help me with any suggestions to make this code work.

 


Answers (3)