Iterate through CheckBoxListItems

I have a checkboxlist control that is bound to an IEnumerable list.
I added an @ref parameter to the CheckBoxList markup to point it towards a declared variable "MyCheckBoxList"

I want to be able to iterate through the list, and disable items that have been checked.

                foreach (var citem in MyCheckBoxList.Items)
            {
                if (citem.Value.ProductItemId == pitem.ProductItemId)
                {
                    citem.Disabled = true;
                }
            }

However, when I try to do that, I get errors about the CheckBoxList being a RenderFragment, and therefore I can't access the Items list.

|Error|CS1579|
foreach statement cannot operate on variables of type 'RenderFragment' because 'RenderFragment' does not contain a public instance or extension definition for 'GetEnumerator'

What is the workaround?

TIA,

Miles

Hi,
I think you that could change approach.
I think that a workaround could be assigning a collection of objects to your CheckBoxList and then looping the collection and changing there the value. Something like:

<RadzenCheckBoxList CheckBoxList Value=@Values TValue="MyType" ValueProperty="Enabled" TextProperty="ObjName"></RadzenCheckBoxList>

@code {
    private IEnumerable<MyType> Values { get; set; }

    private void MyMethod()
    {
        foreach (var citem in Values)
        {
            // do here what you need 
            // eg
            if (citem.ObjName == "EG")
            {
                citem.Enabled = !citem.Enabled;    
            }
        }
    }

    class MyType
    {
        public string ObjName { get; set; }
        public  bool Enabled { get; set; }
    }
}

Regards,