Bold BI®Unlock stunning dashboards with Bold BI®: 35+ widgets, 150+ data sources, AI agent & more. Try it for free!
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.
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
That did the trick. Thanks!
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