listing all form elements

Results 1 to 2 of 2

Thread: listing all form elements

  1. #1
    Join Date
    Dec 1969

    Default listing all form elements

    This must be really simple but can&#039;t figure it out.<BR><BR>I&#039;ve got a form with many elements inside a panel. Who can I access all the elements from a loop?

  2. #2
    Join Date
    Dec 1969

    Default RE: listing all form elements

    Recursion is your friend in this situation :)<BR><BR>Let&#039;s say the panel&#039;s ID was "Panel1", and you wanted to store all the Controls in a HashTable with the Key being the ID of the control and the Value as the control itself!<BR><BR><BR>[code language="VB.NET"]Dim FormControls As New HashTable<BR>WalkControls(Page)<BR><BR>Private Sub WalkControls(ByVal i_Control As Control)<BR> Dim i As Integer<BR> For i = 0 To (i_Control.Controls.Count - 1)<BR> If i_Control.Controls(i).GetType.ToString.EndsWith("T extBox") or Control.Controls(i).GetType.ToString.EndsWith("Dro pDownList") or Control.Controls(i).GetType.ToString.EndsWith("Che ckBox") Then &#039;etc etc etc<BR> FormControls.Add(i_Control.Controls(i).ID, i_Controls(i))<BR> End If<BR> WalkControls(i_Control.Controls(i))<BR> Next<BR>End Sub[/code]<BR><BR>thats some code i wrote (and use) that i pasted in here and ever so slightly modified..... should work, but it is untested

Posting Permissions

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