Title: [Regression 11.3] RadzenDataGrid renders new Data with old dynamic columns after column set changes → ArgumentException "Column 'X' does not belong to table"
Environment
- Radzen.Blazor version: 11.3 and later (regression — worked correctly in versions before 11.3)
Description
I have a RadzenDataGrid<DataRow> with dynamically generated columns (built in a foreach loop from a settings list). The data source is a DataTable converted to IEnumerable<DataRow>.
When I switch both the column settings and the data source at the same time (from a table with 6 columns to a table with 1 column), the grid tries to render the new data using the old column templates. As a result, the template accesses a column that doesn't exist in the new DataTable, and an exception is thrown.
If I set a breakpoint on the switch (radzenGridColumnSetting.Property) line inside the foreach, I can see that the columns markup is built with the correct (new) settings list. However, the grid still renders cell templates of the old columns against the new rows.
This behavior started in version 11.3. The same code works without errors in earlier versions.
Steps to reproduce
- Run the application (full code below).
- Click the SetDataOne button → the grid shows 6 columns (COL1–COL6) with data. Works fine.
- Click the SetDataTwo button → the column settings are replaced with 1 column (COL1) and the data is replaced with a
DataTablethat contains only COL1. - An exception is thrown in the cell template at
@data[radzenGridColumnSetting.Property].
Expected behavior
The grid should dispose/remove the old columns and render the new data only with the new column set (only COL1), as it did in versions before 11.3.
Actual behavior
The grid renders the new rows with the old columns (COL2, COL3, ...), which causes:
System.ArgumentException: 'Column 'COL2' does not belong to table GridDataTwo.'
at System.Data.DataRow.GetDataColumn(String columnName)
at System.Data.DataRow.get_Item(String columnName)
...
[paste full stack trace here]
Code to reproduce
@using System.Data;
<RadzenCard Variant="Variant.Outlined" class="rz-my-4">
<RadzenStack Orientation="Orientation.Horizontal" Gap="0.5rem" AlignItems="AlignItems.Center" Style="margin:1rem">
<RadzenButton Click=@(args => SetDataOne()) Text="SetDataOne" />
<RadzenButton Click=@(args => SetDataTwo()) Text="SetDataTwo" />
</RadzenStack>
</RadzenCard>
<RadzenDataGrid TItem="DataRow" Data="@result" Style="height: 100%; width: 100%;">
<Columns>
@foreach (RadzenGridColumnSetting radzenGridColumnSetting in radzenGridSettingEntity.ListRadzenGridColumnSetting)
{
switch (radzenGridColumnSetting.Property)
{
default:
<RadzenDataGridColumn Title=@radzenGridColumnSetting.Title Property=@radzenGridColumnSetting.PropertyType TItem="DataRow" Width=@radzenGridColumnSetting.WidthValue TextAlign=@radzenGridColumnSetting.TextAlign Visible=@radzenGridColumnSetting.Visible>
<Template Context="data">
<span title=@data[radzenGridColumnSetting.Property]>@data[radzenGridColumnSetting.Property]</span>
</Template>
</RadzenDataGridColumn>
break;
}
}
</Columns>
</RadzenDataGrid>
@code {
private RadzenGridSetting radzenGridSettingEntity = new RadzenGridSetting("radzenGridSettingEntity");
private IEnumerable<DataRow> result;
private void SetDataOne()
{
radzenGridSettingEntity.ListRadzenGridColumnSetting = SetGridSettingsOne();
result = SetGridDataOne().AsEnumerable();
StateHasChanged();
}
private List<RadzenGridColumnSetting> SetGridSettingsOne()
{
List<RadzenGridColumnSetting> gridSettings = new();
gridSettings.Add(new RadzenGridColumnSetting("COL1 Text", "COL1", "DateTime?", true, 80, TextAlign.Center, 0));
gridSettings.Add(new RadzenGridColumnSetting("COL2 Text", "COL2", "Decimal?", true, 80, TextAlign.Center, 1));
gridSettings.Add(new RadzenGridColumnSetting("COL3 Text", "COL3", "Decimal?", true, 80, TextAlign.Center, 2));
gridSettings.Add(new RadzenGridColumnSetting("COL4 Text", "COL4", "Decimal?", true, 80, TextAlign.Center, 3));
gridSettings.Add(new RadzenGridColumnSetting("COL5 Text", "COL5", "DateTime?", true, 80, TextAlign.Center, 4));
gridSettings.Add(new RadzenGridColumnSetting("COL6 Text", "COL6", "DateTime?", true, 80, TextAlign.Center, 5));
return gridSettings;
}
private DataTable SetGridDataOne()
{
var table = new DataTable("GridDataOne");
table.Columns.Add("COL1", typeof(DateTime));
table.Columns.Add("COL2", typeof(decimal));
table.Columns.Add("COL3", typeof(decimal));
table.Columns.Add("COL4", typeof(decimal));
table.Columns.Add("COL5", typeof(DateTime));
table.Columns.Add("COL6", typeof(DateTime));
table.Rows.Add(new DateTime(2026, 1, 1), 100.50m, 200.00m, 15.75m, new DateTime(2026, 1, 1), new DateTime(2026, 1, 1));
table.Rows.Add(new DateTime(2026, 1, 2), 110.25m, 195.40m, 16.10m, new DateTime(2026, 1, 1), new DateTime(2026, 1, 1));
table.Rows.Add(new DateTime(2026, 1, 3), 98.70m, 210.15m, 14.90m, new DateTime(2026, 1, 1), new DateTime(2026, 1, 1));
table.Rows.Add(new DateTime(2026, 1, 4), 120.00m, 205.80m, 17.35m, new DateTime(2026, 1, 1), new DateTime(2026, 1, 1));
table.Rows.Add(new DateTime(2026, 1, 5), 105.30m, 199.99m, 15.00m, new DateTime(2026, 1, 1), new DateTime(2026, 1, 1));
table.Rows.Add(new DateTime(2026, 1, 6), 115.60m, 220.45m, 18.20m, new DateTime(2026, 1, 1), new DateTime(2026, 1, 1));
table.Rows.Add(new DateTime(2026, 1, 7), 95.10m, 189.30m, 13.85m, new DateTime(2026, 1, 1), new DateTime(2026, 1, 1));
table.Rows.Add(new DateTime(2026, 1, 8), 130.75m, 230.00m, 19.40m, new DateTime(2026, 1, 1), new DateTime(2026, 1, 1));
return table;
}
private void SetDataTwo()
{
radzenGridSettingEntity.ListRadzenGridColumnSetting = SetGridSettingsTwo();
result = SetGridDataTwo().AsEnumerable();
StateHasChanged();
}
private List<RadzenGridColumnSetting> SetGridSettingsTwo()
{
List<RadzenGridColumnSetting> gridSettings = new();
gridSettings.Add(new RadzenGridColumnSetting("COL1 Text", "COL1", "Decimal?", true, 80, TextAlign.Center, 0));
return gridSettings;
}
private DataTable SetGridDataTwo()
{
var table = new DataTable("GridDataTwo");
table.Columns.Add("COL1", typeof(decimal));
table.Rows.Add(11.20m);
table.Rows.Add(12.80m);
table.Rows.Add(9.45m);
table.Rows.Add(15.00m);
table.Rows.Add(8.10m);
table.Rows.Add(13.33m);
table.Rows.Add(14.99m);
return table;
}
private class RadzenGridSetting
{
public RadzenGridSetting(string radzenGridName)
{
RadzenGridName = radzenGridName;
}
public string RadzenGridName { get; set; }
public List<RadzenGridColumnSetting> ListRadzenGridColumnSetting { get; set; } = new List<RadzenGridColumnSetting>();
}
private class RadzenGridColumnSetting
{
public RadzenGridColumnSetting(string title, string property, string type, bool visible, int width, Radzen.TextAlign textAlign, int order)
{
Title = title;
Property = property;
Type = type;
Visible = visible;
Width = width;
TextAlign = textAlign;
Order = order;
}
public string Title { get; set; }
public string Property { get; set; }
public string Type { get; set; }
public string PropertyType
{
get { return string.IsNullOrEmpty(Type) ? Property : "(" + Type + ")it[\"" + Property + "\"]"; }
}
public bool Visible { get; set; }
public int Width { get; set; }
public string WidthValue
{
get { return Width.ToString() + "px"; }
}
public Radzen.TextAlign TextAlign { get; set; } = TextAlign.Left;
public int Order { get; set; }
}
}
Additional notes
- This is a regression: the issue started in version 11.3. The same code works without errors in [previous version, e.g. 11.2.x].
- It looks like the grid re-renders rows with the new
Databefore the oldRadzenDataGridColumncomponents are removed from its internal columns collection.