1

我是 Blazor 和 Blazorise 的新手......在研究这个组件时,我似乎找不到任何材料教如何在 Blazorise DataGrid 的 EditTemplate 内的 TextEdit 中绑定变量。

在我的 Blazorise DataGrid 中,我有一个 DataColumn(请参见下面的代码):

<DataGridColumn
    Caption="Description"
    Editable="true"
    TItem="ProductVo"
    Field="@nameof(ProductVo.Description)">
        <DisplayTemplate>
            @($"{(context as ProductVo)?.Description}")
        </DisplayTemplate>
        <EditTemplate>
            <Validation UsePattern="true">              
                <TextEdit @bind-Text="context.CellValue" Text="@((string)context.CellValue)" Pattern="^.{3,200}$">
                    <Feedback>
                        <ValidationError>This field must be between 3 and 200 characters long.</ValidationError>
                    </Feedback>
                </TextEdit>
            </Validation>
        </EditTemplate>
</DataGridColumn>

在我的<TextEdit>中,我可以使用以下代码在编辑时显示该值:

Text="@((string)context.CellValue)"

但它不保存,因为我无法绑定context.CellValueusing @bind-Text="context.CellValue"

请帮助我学习如何使用 Blazorise DataGrid,在此先感谢!

4

1 回答 1

3

您错过了该TextChanged活动,负责更新context. 这应该有效:

<TextEdit Text="@((string)context.CellValue)" TextChanged="@(v => ( (CellEditContext)context ).CellValue = v)" Pattern="^.{3,200}$">
于 2021-02-10T04:46:38.293 回答