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
|
<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();
}
}
}
|
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