Ok, Using Studio 2010. I have a webpage with 5 DropDownList boxes that all will have the same data (when I am done the number will be more like 30 of them). Instead of loading the datasource for each after a dropdownlist item is selected, I would like to do this in a loop. In order to accomplish this, I need an array of DropDownLists. Borrowed a bit of code throughout my numerous searches, but can't modify it to support system.web.ui. The section of code here is supposed to find controls with "like" names and convert them into an array. I am passing the name of the page calling the Class in 'webPage' and the control name 'ddlE' in 'controlName' as variables. Here is the code:
Call from webpage in Page_Load Event:
mddEmployee = ControlArrayUtils.getControlArray(Me,"ddlE")
getControlArray class:
Public Shared Function getControlArray(ByVal webPage As System.Web.UI.Page, _
ByVal controlName As String, Optional ByVal separator As String = "") As System.Array
Dim i As Short
Dim startOfIndex As Short
Dim alist As New ArrayList
Dim controlType As System.Type
Dim ctl As System.Web.UI.Control
Dim ctrls() As System.Web.UI.Control
Dim strSuffix As String
Dim maxIndex As Short = -1 'Default
For Each ctl In webPage.Controls
startOfIndex = ctl.ID.ToLower.IndexOf(controlName.ToLower & separator)
If startOfIndex = 0 Then
strSuffix = ctl.ID.Substring(controlName.Length)
If IsInteger(strSuffix) Then
If Val(strSuffix) > maxIndex Then _
maxIndex = Val(strSuffix)
End If
End If
Next ctl
If maxIndex > -1 Then
For i = 0 To maxIndex
Dim aControl As System.Web.UI.Control = getControlFromName(webPage, controlName, i, separator)
If Not (aControl Is Nothing) Then
controlType = aControl.GetType
End If
alist.Add(aControl)
Next
End If
Return alist.ToArray(controlType)
End Function
'webPage' and 'controlName' both load fine, but my problem is the underline piece of code. The ctl.ID value does not return the controls I have on the form (ddlE1, ddlE2, ddlE3, etc...). It returns an ID value of ctl001 or ctl002. How do I actually get the name of the control?