Search code examples
c#.netblazorradzen

Change RadzenDataGridColumn background color


<RadzenDataGridColumn  
    TItem="Finance" 
    Width="50%" Resizable
    Property="AcurName" 
    Filterable="false"  
    style="background:red"  
    Frozen="true" Title="Price"
/>

Error:

System.InvalidOperationException: 
  Object of type 
    'Radzen.Blazor.RadzenDataGridColumn`1[
       [Goldproj.Finance, 
        Goldproj, 
        Version=1.0.0.0, 
        Culture=neutral, 
        PublicKeyToken=null]]' 
  does not have a property matching the name 'style'.
  
   at Microsoft.AspNetCore.Components.Reflection.ComponentProperties
     .ThrowForUnknownIncomingParameterName(Type targetType, String parameterName)
   
   at Microsoft.AspNetCore.Components.Reflection.ComponentProperties
     .SetProperties(ParameterView& parameters, Object target)
   
   at Radzen.Blazor.RadzenDataGridColumn`1.<>n__0(ParameterView parameters)
   
   at Radzen.Blazor.RadzenDataGridColumn`1.SetParametersAsync(ParameterView parameters)

I tried to give a background, but nothing works.


Solution

  • <RadzenDataGridColumn TItem="Finance" Property="AcurName" Title="Price" Width="50%">
        <Template Context="data">
            <div class="custom-column-bg">
                @data.AcurName
            </div>
        </Template>
    </RadzenDataGridColumn>
    
    .custom-column-bg {
        background-color: red; /* or any other color */
    }
    

    RadzenDataGridColumn does not directly support adding CSS classes to its cells via a property. Instead, you have to use the Template of the column to customize and apply the CSS class to each cell.