Calling custom async method when checkbox is changed

We are constructing a question/answer grid where each row represents a question and answer.  The answer control can either be a checkbox, dropdown or textbox.  The data binding and display of the grid is working well so far.  We are running into trouble binding the changed events for the different controls.  

Here is our grid:

<SfGrid @ref="_grid" TValue="ViewType" DataSource="@_items" AllowTextWrap="true">
<GridColumns>
<GridColumn Field=@nameof(ViewType.QuestionText) HeaderText="Question" Width="150"/>
    <GridColumn HeaderText="Answer" TextAlign="TextAlign.Left" Width="100">
    <Template>
    @{
      var row = (context as ViewType);
     if (row.AnswerTypeId.IsCheckbox())
{
        <SfCheckBox Checked="@row.AnswerBool" HELP_WITH_BINDING />
      }
      else if (row.AnswerTypeId.IsDropdown())
      {
       <SfDropDownList TValue="Guid?" TItem="DisplayValueResponse" Value="@row.AnswerId" Placeholder="@GetPlaceholder(row.QuestionId)">
         <DropDownListEvents TValue="Guid?" TItem="DisplayValueResponse" Created="@(() => MarkControlDataBound(row.QuestionId))"/>
         <SfDataManager Url="@PossibleAnswersUrl(row)" Adaptor="Adaptors.WebApiAdaptor" />
          <DropDownListFieldSettings Text="Display" Value="Value" />
        </SfDropDownList>
      }
else if (row.AnswerTypeId.IsTextbox())
      {
       <SfTextBox Value="@row.AnswerText" />
      }
else
      {
       <div>not implemented</div>
      }
    }
    </Template>
    </GridColumn>
  </GridColumns>
</SfGrid>

Looking at the <SfCheckBox> tag with the HELP_WITH_BINDING, we would like to be able to call a method (async) that would pass in both the row Id as well as the changed value.  Here are two ways we tried to go about doing that:

CheckChanged="@MethodAsync"

Using this method, the signature won't allow us to pass another parameter such as the row Id.

CheckChanged="@(() => MethodAsync(row.QuestionId, ???)"

Using this method, we are not sure how we can pull out the checked value to pass to the method.

Any help with this would be greatly appreciated.




3 Replies

TS Thaneegairaj Sankar Syncfusion Team December 1, 2021 12:49 PM UTC

Hi Jeff,


Thank you for contacting Syncfusion support. 


We have checked your reported requirement and we can be able to achieve your requirement in sample level, please find the below code snippets


In Index.razor file

<SfCheckBox Checked="isChecked" Label="Change" TChecked="bool"

CheckedChanged="e => onChange(e, context)"></SfCheckBox>

 

@code {

    private bool isChecked = true;

    private string context = "true";

    public async void onChange(bool arg, string value)

    {

        //onChange Event triggered

    }

}


For your reference we have prepared a sample,


Sample link: https://www.syncfusion.com/downloads/support/directtrac/general/ze/Server5.0-1417450965-1123285951


Please get back to us, if you need any further assistance on this.


Regards,

Thaneegairaj S



JV Jeff Voigt December 1, 2021 01:24 PM UTC

That did the trick.  Thanks!



TS Thaneegairaj Sankar Syncfusion Team December 2, 2021 05:40 AM UTC

Hi Jeff,


Thanks for the update.


We are happy to hear that your requirement has been fulfilled. Please feel free to contact us if you need any further assistance on this.


Regards,

Thaneegairaj S


Loader.
Up arrow icon