Array of checkboxes - binded to an array

Dear Syncfusion,

I have to display a group of checkboxes, binding their value to an array. What I tried is this:

<td>
            @for(int i = 2011; i< 2021; i++)
            {
                 <SfCheckBox Label="@i.ToString()" LabelPosition="LabelPosition.Before" @bind-Checked="@x[i-2011]"></SfCheckBox><br>
            }
        </td>
@code {
bool[] x = new bool[10] { false, false, false, false, false, false, false, false, false, false};
}

When I run the app, the checkboxes are frozen, they can not be checked.

How can this be done properly, please?

Thanks!


2 Replies

PE Peter November 22, 2021 04:30 PM UTC

Ok, I found it out: I have to create a local variable, like this:

@for(int i = 0; i< 10; i++)
            {
                int localI = i;
                 <SfCheckBox Label="@localI.ToString()" LabelPosition="LabelPosition.Before" @bind-Checked="@x[localI]" @onchange="onChange"></SfCheckBox><br>
            }

This way all is fine.



GK Gayathri KarunaiAnandam Syncfusion Team November 23, 2021 03:45 AM UTC

Hi Peter, 

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, 
Gayathri K 


Loader.
Up arrow icon