@bind-value not updated in grid

HI Team,

Can you help me understand where am I missing.  I am unable to bind value of a combobox when we are creating grid dynamically.

I tried in several ways but failed to show the selected value back in grid after editing.


Regards

Pavan Kumar




Attachment: SyncFusionGridApp_210928_e8fc789c.zip

3 Replies

JP Jeevakanth Palaniappan Syncfusion Team September 28, 2021 01:01 PM UTC

Hi Pavan, 

Greetings from Syncfusion support. 

We have validated your query and when using EditTemplate for Dynamic object, it is not possible to use the @bind-Value property. So we suggest you to use the Value property and ensure to handle the edited value update action programmatically in OnActionBegin event of Grid. Please refer the below codes and the modified sample for your reference. 

<SfGrid DataSource="@Orders"> 
    <GridEvents OnActionBegin="ActionBeginHandler" TValue="OrdersDetails"></GridEvents> 
    <GridColumns> 
        <GridColumn Field="Account" 
                    HeaderText="Account" 
                    EditType="EditType.DropDownEdit" 
                    TextAlign="TextAlign.Right" 
                    Width="120"> 
            <EditTemplate> 
                @{ 
                    var ord = context as OrdersDetails; 
                    ComboBoxValue = (string)DataUtil.GetDynamicValue(ord as DynamicObject, "Account"); 
                    <SfComboBox ID="Account" Placeholder="Select an Account" Value="@ComboBoxValue" TItem="string" TValue="string" DataSource="@accounts"> 
                        <ComboBoxEvents TValue="string" TItem="string" ValueChange="ValueChangeHandler"></ComboBoxEvents> 
                    </SfComboBox> 
                } 
            </EditTemplate> 
 
 
        </GridColumn> 
    </GridColumns> 
</SfGrid> 
 
@code{ 
    public string ComboBoxValue { get; set; } 
    public void ValueChangeHandler(Syncfusion.Blazor.DropDowns.ChangeEventArgs<string, string> args) { 
        ComboBoxValue = args.Value; 
    } 
 
    public async void ActionBeginHandler(ActionEventArgs<OrdersDetails> Args) 
    { 
        if (Args.RequestType.Equals(Syncfusion.Blazor.Grids.Action.Save)) 
        { 
            if (Args.Action == "Add") 
            { 
                Orders.Add(Args.Data); 
            } 
            else 
            { 
                //Orders.Remove(Args.Data); 
                //Orders.Add(Args.Data); 
            } 
            if (Args.Action == "Edit") 
            { 
                ((OrdersDetails)Args.Data).TrySetMember(new DataSetMemberBinderClone("Account", false), ComboBoxValue); 
            } 
        } 
        if (Args.RequestType.Equals(Syncfusion.Blazor.Grids.Action.Delete)) 
        { 
 
        } 
        await Task.CompletedTask; 
    } 
 
    public class DataSetMemberBinderClone : SetMemberBinder 
    { 
        public DataSetMemberBinderClone(string name, bool ignoreCase) 
            : base(name, ignoreCase) 
        { 
        } 
 
        public override DynamicMetaObject FallbackSetMember(DynamicMetaObject target, DynamicMetaObject value, DynamicMetaObject errorSuggestion) 
        { 
            throw new NotImplementedException(); 
        } 
    } 
} 
 



Please get back to us if you have any other queries. 

Regards, 
Jeevakanth SP. 



PK Pavan Kumar September 29, 2021 10:23 AM UTC

Hi Jeevakanth,


Thank you so much for the quick help,  that worked for us and helped us move ahead. Is there any way we can find the datatable associated to the Grid.


Regards


Pavan




JP Jeevakanth Palaniappan Syncfusion Team September 30, 2021 05:42 AM UTC

Hi Pavan, 

Query: Is there any way we can find the datatable associated to the Grid. 

We are quite unclear about your requirement. So please share us the below details. 

  1. Share us more information on your query.
  2. Do you want to get the data rendered in the grid?
  3. Share us any screenshot or video demo showing your requirement.

The above details will be helpful for us to validate your query and to provide you with a better solution as early as possible. 

Regards, 
Jeevakanth SP. 


Loader.
Up arrow icon