Another CheckBoxList question

Results 1 to 2 of 2

Thread: Another CheckBoxList question

  1. #1
    Join Date
    Dec 1969

    Default Another CheckBoxList question

    Is there a way to loop through all the CheckBoxLists in a Page/Control without accessing them by their ids, say, by using a For Each loop perhaps? Here&#039;s the code I&#039;m currently trying to use:<BR><BR> Dim cbl As CheckBoxList<BR> For Each cbl In Page.Controls<BR><BR> (code...)<BR><BR> Next<BR><BR>I&#039;m getting the error Specified Cast is Not Valid on the For Each Statement. I looked up the error on Microsoft and it says that I am not setting the ID property of the checkboxes when I programmatically add them, but I actually am. Any ideas? <BR><BR>Thanks!

  2. #2
    Join Date
    Dec 1969

    Default RE: Another CheckBoxList question

    I think the invalid cast error is due to the fact that Page.Controls collection holds the collection of CONTROL objects and you are trying to cast a CONTROL object to a CheckBoxList.<BR><BR>I am not sure, but the controls on a page are not organized by type like the DOM. They are added in (order?) of addition and so are indexed as an array ( Page.Controls[x]) so you would have to know where in the array they existed.<BR><BR>If that is the case, consider using the array.binarysearch() method to locate your controls.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts