1
votes

I am using sync fusion grid in blazor server app. Inside grid I am using dropdown list. I wanna trigger the even on dropdown change event. When I try to bind the event using following code its giving me error "cannot convert from method group to eventcallback". Please help.

Below is the razor HTML code

<GridColumn HeaderText="Action" TextAlign="TextAlign.Center" Width="95">
    <Template>
        <SfDropDownList TItem="ActionDDLVM" Value="@((context as ActionDDLVM).Id)" TValue="string" PopupHeight="100px" Placeholder="Action" DataSource="@LstAction">
            <DropDownListEvents TValue="string" TItem="ActionDDLVM" OnValueSelect="OnSelect" ValueChange="ValueChange"></DropDownListEvents>
            <DropDownListFieldSettings Text="Text" Value="Id"></DropDownListFieldSettings>
        </SfDropDownList>
    </Template>
</GridColumn>

Below is the code in C# component partial class

public void OnSelect(SelectEventArgs args)
{

}

public void ValueChange(Syncfusion.Blazor.DropDowns.ChangeEventArgs<string> args)
{
    // you can get changed value in args.Value
}
2
Are you missing a type? "Declaration public EventCallback<ChangeEventArgs<TValue, TItem>> ValueChange { get; set; }" - Fildor

2 Answers

1
votes
Event arguments of **OnValueSelect** and **ValueChange** were defined wrongly. Please find the modified code example below. 
<GridColumn HeaderText="Action" TextAlign="TextAlign.Center" Width="95">
            <Template>
              <SfDropDownList TItem="ActionDDLVM" Value="@((context as ActionDDLVM).Id)" TValue="string" PopupHeight="100px" Placeholder="Action" DataSource="@LstAction">
                       <DropDownListEvents TValue="string" TItem="ActionDDLVM" OnValueSelect="OnSelect" ValueChange="ValueChange"></DropDownListEvents>
                   <DropDownListFieldSettings Text="Text" Value="Id"> 
                     </DropDownListFieldSettings>
              /SfDropDownList>
             </Template>
</GridColumn>
    
public void OnSelect(SelectEventArgs<ActionDDLVM> Args)
{
  
}
public void ValueChange(ChangeEventArgs<string, ActionDDLVM> Args)
{
 
}
1
votes

The ValueChanged property is declared as EventCallback<TValue>, where TValue is string in your example. This means the method parameter it's expecting is actually string, and not ChangeEventArgs<string>. Therefore, changing your ValueChange method to use a string instead ought to fix this:

public void ValueChange(string value)
{
}

In contrast, the OnChange property is declared that way:

public EventCallback<ChangeEventArgs> OnChange

So perhaps that is what led to the confusion.