I have inherited a web site that I have to update but I am having problems with a drop down list. There are two asp.net drop down list boxes on a page. They are ddlReminderUser1 and ddlReminderUser2. When the page loads a function pulls data from a SQL DB and sets some hidden field values. Based on these values the drop down lists are being set.
The problem is that there are two drop down lists and only one is setting the selected value, the other is not.
Here is HTML for the drop drown lists:
<asp:DropDownList runat="server" ID="ddlReminderUser1" AutoPostBack="true" CssClass="text-primary mt-1 width125" Visible="false" OnSelectedIndexChanged="ddlReminderUser1_SelectedIndexChanged"></asp:DropDownList>
<asp:ImageButton ID="btnXUser1" runat="server" AlternateText="X" ImageUrl="~/Images/red-x-md15x15.png" ToolTip="Click to remove user 1" Visible="false" />
<br />
<asp:DropDownList runat="server" ID="ddlReminderUser2" AutoPostBack="true" CssClass="text-primary mt-1 width125" Visible="false" OnSelectedIndexChanged="ddlReminderUser2_SelectedIndexChanged"></asp:DropDownList>
<asp:ImageButton ID="btnXUser2" runat="server" AlternateText="X" ImageUrl="~/Images/red-x-md15x15.png" ToolTip="Click to remove user 2" Visible="false" />
And here is the code behind (in VB):
'Set user names in ddl's
With ddlReminderUser1
.Visible = True
If getAdList(1) < 1 Then
message = "Can't get user list from AD for Notifications.\nError: SQL104\nPlease contact the Help Desk for support."
alertMessage(message)
.SelectedIndex = 0
Else
.SelectedValue = hUser1.Value.ToString()
btnXUser1.Visible = True
End If
End With
'Check for second email address
If ddlNumberOfUsers.SelectedIndex = 2 Then
ddlReminderUser2.Visible = True
If getAdList(2) < 1 Then
message = "Can't get user list from AD for Notifications.\nError: SQL104\nPlease contact the Help Desk for support."
alertMessage(message)
ddlReminderUser2.SelectedIndex = 0
Else
ddlReminderUser2.SelectedValue = hUser2.Value.ToString()
btnXUser2.Visible = True
End If
'With ddlReminderUser2
' .Visible = True
' If getAdList(2) < 1 Then
' message = "Can't get user list from AD for Notifications.\nError: SQL104\nPlease contact the Help Desk for support."
' alertMessage(message)
' .SelectedIndex = 0
' Else
' .SelectedValue = hUser2.Value.ToString()
' btnXUser2.Visible = True
' End If
'End With
End If
The commented out section gets the exact same result. I though maybe the With statement my be the problem but it doesn't seem to be.
The function getAdList is working fine because when I check the drop down list it has the list of AD names in it.
This is what I am getting:
The drop down list that says select user should be displaying the second name, which I verified is in the DB and the hidden field value correctly. What am I missing? I have been staring at this section of code now for a few hours and nothing I do works.
Anyone have an idea?
And thanks in advance...

If ddlNumberOfUsers.SelectedIndex = 2... are you sure the selected index is2and not1? (considering that "Number of Users 1" is probably the first item)hUser2.Valuewhile stepping through? Are there any items inddlReminderUser2when you are setting the selected values? Are there any items with the same value as that you are trying to set? What doesgetAdList()do?