I have inherited a website which fills all the dropdown lists on the page during the page load event. Code below:
I have another dropdown list which is populated with other data but the above code appends to this dropdown list. Is there a way I can modify the code above to exclude a specific combo box/boxes?
Code:
Private Sub FillDropDowns()
Dim Ctrl As Object
Dim j As Integer
For Each Ctrl In Page.Controls
For i As Integer = 0 To Ctrl.Controls.Count() - 1 'Step 1
If Ctrl.Controls.Item(i).ToString().Equals("System.Web.UI.WebControls.DropDownList") Then
'ADD A DEFAULT TO THE DROPDOWNS
Dim defItem As New ListItem
defItem.Text = " -- select -- "
defItem.Value = ""
Ctrl.Controls.Item(i).Items.Add(defItem)
'ADD THE VALUES 1 to 31 TO EACH DROPDOWN
For j = 1 To 31
Dim liItem As New ListItem
liItem.Text = j.ToString
liItem.Value = j.ToString
Ctrl.Controls.Item(i).Items.Add(liItem)
Next
End If
Next
Next
End Sub
I have another dropdown list which is populated with other data but the above code appends to this dropdown list. Is there a way I can modify the code above to exclude a specific combo box/boxes?