I have a form that has many dynamically generated checkboxes. At runtime, how can I iterate through each of them so I can get their value and IDs?
I know that this is old, but It was easy as I can imagine.
Just add all checkboxes into a List
, all checkboxes state are in the list and even if they change in the UI in the list changes too.
List checkboxes = new List();
checkboxes.Add(chk1);
checkboxes.Add(chk2);
//So add all checkboxes you wanna iterate
foreach(Checkbox checkbox in checkboxes){
//Do something using checkbox object
}
Hope this helps :)