Blazor Server - How to set value from child to parent

Cenk 1,036 Reputation points
2022-08-03T12:22:25.66+00:00

Hi,

I have a grid and inside of one of the columns, there is this dropdown. I would like to pass the value of drop down to this grid column. Is there a way to do it?

Here is HTML portion;

   ...  
    <RadzenDataGridColumn TItem="OrderDetail" Property="VendorName" Title="Vendor" Width="200px">  
                                    <EditTemplate Context="orderDetail">  
                                        <RadzenDropDownDataGrid TValue="string"  AllowFiltering="true" AllowClear="true" FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive" FilterOperator="StringFilterOperator.StartsWith"  
                                                                Data=@_vendors Count="5" TextProperty="Name" ValueProperty="Name"  
                                                                Class="w-100" Change=@(args => OnChange(args))/>  
                                        @*<RadzenTextBox @bind-Value="orderDetail.VendorName" Style="width: 100%; display: block" Name="VendorName"/>*@  
                                        <RadzenRequiredValidator Text="Vendor Name is required" Component="VendorName" Popup="true" Style="position: absolute"/>  
                                    </EditTemplate>  
                                </RadzenDataGridColumn>  
    ...  

Here is code portion:
IList<Order?> SelectedOrders { get; set; }

    IEnumerable<Order?> _orders = new List<Order?>();  
    IEnumerable<Vendor?> _vendors;  
  
    RadzenDataGrid<Order?> _grid;  
    RadzenDataGrid<OrderDetail> _gridDetail;  
  
  
    protected override async Task OnInitializedAsync()  
    {  
        _orders = await ViewAllOrdersUseCase.ExecuteAsync();  
        SelectedOrders = new List<Order?> { _orders.FirstOrDefault() };  
  
        _vendors = await ViewAllVendorsUseCase.ExecuteAsync();  
  
    }  
  
  
    void OnChange(object value)  
    {  
        var str = value;  
          
          
    }  
Developer technologies | .NET | Blazor
{count} votes

1 answer

Sort by: Most helpful
  1. Cenk 1,036 Reputation points
    2022-08-03T19:40:19.297+00:00

    Do OrderDetail and Vendor have to have a relationship in order to save?

    <RadzenDataGridColumn TItem="OrderDetail" Property="VendorName" Title="Vendor" Width="200px">  
                                    <EditTemplate Context="orderDetail">  
                                        <RadzenDropDownDataGrid TValue="string"  AllowFiltering="true" AllowClear="true" FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive" FilterOperator="StringFilterOperator.StartsWith"  
                                                                Data=@_vendors Count="5" TextProperty="Name" ValueProperty="Name"  
                                                                Class="w-100" @bind-Value="orderDetail.VendorName"/>  
                                         
                                        <RadzenRequiredValidator Text="Vendor Name is required" Component="VendorName" Popup="true" Style="position: absolute"/>  
                                    </EditTemplate>  
                                </RadzenDataGridColumn>  
    

    I am getting this error;

     System.InvalidOperationException: Cannot find component with Name VendorName  
           at Radzen.Blazor.ValidatorBase.ValidateModel(Object sender, ValidationRequestedEventArgs args)  
           at Microsoft.AspNetCore.Components.Forms.EditContext.Validate()  
           at Radzen.Blazor.RadzenDataGrid`1.UpdateRow(TItem item)  
           at IMS.WebApp.Pages.Orders.OrderList.SaveRowDetail(OrderDetail orderDetail) in C:\Users\197199\Source\Repos\IMS.WebApp\IMS.WebApp\Pages\Orders\OrderList.razor:line 370  
           at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)  
           at Radzen.Blazor.RadzenButton.OnClick(MouseEventArgs args)  
           at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)  
           at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)  
    

    While trying to save;

    <EditTemplate Context="detail">  
                                        <RadzenButton Icon="check" ButtonStyle="ButtonStyle.Primary" Class="m-1" Click="@(args => SaveRowDetail(detail))">  
                                        </RadzenButton>  
     </EditTemplate>  
      
    .....  
      
    async Task SaveRowDetail(OrderDetail orderDetail)  
        {  
            if (orderDetail == _detailToInsert)  
            {  
                _detailToInsert = null;  
            }  
      
            await _gridDetail.UpdateRow(orderDetail);  
        }  
    
    
    
    
    
    
    
      
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.