We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Bind value in EditTemplate throw own component

Hi,

i need a little help with databinding.

I want to bind ItemCategory of my object in EditTemplate throw my component


///////// ItemCategoryDropDownList.razor  ////////////////////////////////////////////////////

@inject AppCache AppCache

<SfDropDownList @bind-Value="@Value"

                Placeholder="@DomainResource.ItemCategory"

                DataSource="@AppCache.ItemCategories()"

                TItem="ItemCategory"

                TValue="ItemCategory">

    <DropDownListFieldSettings Text="@nameof(ItemCategory.Name)" Value="ItemCategory">

    </DropDownListFieldSettings>

</SfDropDownList>


@code {


    [Parameter]

    public ItemCategory Value { get; set; }


    [Parameter]

    public EventCallback<ItemCategory> ValueChanged { get; set; }

}

///////// end ItemCategoryDropDownList.razor  ////////////////////////////////////////////////////



In this grid

///////// Grid.razor  ////////////////////////////////////////////////////

 <GridColumn Field="@nameof(ItemLoan.ItemCategory)"

                    HeaderText="@TextResource.Category"

                    Width="200">

            <Template>

                @{

                    var item = (context as ItemLoan);

                }

                <span>@item.ItemCategory?.Name</span>

            </Template>

            <EditTemplate>

                @{

                    var item = (context as ItemLoan);

                }

                <SfDropDownList @bind-Value="@item.ItemCategory"

                                Placeholder="@DomainResource.ItemCategory"

                                DataSource="@AppCache.ItemCategories()"

                                TItem="ItemCategory"

                                TValue="ItemCategory">

                    <DropDownListFieldSettings Text="@nameof(ItemCategory.Name)" Value="@nameof(ItemCategory.Id)">

                    </DropDownListFieldSettings>

                </SfDropDownList>

                @* <ItemCategoryDropDownList @bind-Value="@item.ItemCategory" />*@

            </EditTemplate>

        </GridColumn>

///////// end Grid.razor  ////////////////////////////////////////////////////

When I place 

<ItemCategoryDropDownList @bind-Value="@item.ItemCategory" />

into edit template , and end my editting and hit save button this Error occure.

But with same code but wiyhout component. Value is passed correctly.


Error: System.NullReferenceException: Object reference not set to an instance of an object.

   at Syncfusion.Blazor.Grids.Internal.Edit`1.EndEdit()

   at Syncfusion.Blazor.Grids.Internal.DialogEdit`1.<BuildRenderTree>b__0_11()

   at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)

   at Syncfusion.Blazor.Internal.SfBaseUtils.InvokeEvent[T](Object eventFn, T eventArgs)

   at Syncfusion.Blazor.Buttons.SfButton.OnClickHandler(MouseEventArgs args)

   at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)

   at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)


Attachment: Screenshots_6a995aa2.zip

1 Reply

SP Sarveswaran Palani Syncfusion Team January 23, 2023 03:22 AM UTC

Hi Pavel,


Greetings from Syncfusion support.

From your query, we prepared sample based on your shared code snippet. But we’re unable to reproduce the reported error at our end. If we misunderstood your query, kindly reproduce the reported issue in the provided sample or share simple issue reproducible sample to us. It’ll will be very helpful for us to validate the reported query at our end and provide the solution as early as possible. Kindly refer the attached sample and video demo for your reference.

Regards,
Sarvesh


Attachment: SfGridTemplateEdit_1669613d.zip

Loader.
Up arrow icon