Checkbox doesn't change value

Hello, I have a problem changing the value of a CheckBox(the blue tick doesn't appear if it was false initially). I use the CheckBox as a template inside of a grid column. I check a condition and based on the returned value I set the Checked property of CheckBox. Then if I use an event like onchange the value doesn't change. If I remove the event I can change the value(the blue tick appears).Here is my code:
<Template>
                    @{
                        var point = (context as Point);
                        bool isChecked;
                        if(point.PointName == Name){
                            isChecked = true;
                        }else{
                            isChecked = false;
                        }
                        <SfCheckBox Checked = "@isChecked" @onchange = "OnChange"></SfCheckBox>
                    }
</Template>
private void OnChange(Microsoft.AspNetCore.Components.ChangeEventArgs args)
{
  Console.WriteLine(args.Value);
}



3 Replies 1 reply marked as answer

MK Mohan Kumar Ramasamy Syncfusion Team October 20, 2020 10:33 AM UTC

Hi Tom, 
 
We have checked your reported query, we have resolved your reported issue using two way binding Checked property. Please refer below code snippets. 
 
<SfCheckBox @bind-Checked="@isChecked" Label="CheckBox" ValueChange="ValueChange" TChecked="bool"></SfCheckBox> 
@code { 
 
 
    private bool isChecked = false; 
    private string point = "one"; 
 
    private void ValueChange(ChangeEventArgs<bool> args) 
    { 
        if (point == "one") 
        { 
            isChecked = true; 
            point = "two"; 
        } 
        else 
        { 
            isChecked = false; 
            point = "one"; 
        } 
        Console.WriteLine(args.Checked); 
    } 
} 
 
 
For your reference, we have prepared a sample based on this, please refer below link. 
 
 
Please let us know, if you need any further assistance. 
 
Regards, 
Mohan kumar R 


Marked as answer

TD Tom Dimos October 20, 2020 01:05 PM UTC

This wasn't exactly what I intended to do but @bind-Checked was part of it. Thanks!!!


MK Mohan Kumar Ramasamy Syncfusion Team October 21, 2020 11:08 AM UTC

Hi Tom, 
 
Thanks for the update get back to us, if you need further assistance on this then. 
 
Regards, 
Mohan kumar R 


Loader.
Up arrow icon