2

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>
&nbsp;
<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>
&nbsp;
<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:

enter image description here

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...

4
  • 1
    If ddlNumberOfUsers.SelectedIndex = 2 ... are you sure the selected index is 2 and not 1? (considering that "Number of Users 1" is probably the first item) Commented Feb 15, 2018 at 21:03
  • Have you set a breakpoint and stepped through the code? Have you checked the value of hUser2.Value while stepping through? Are there any items in ddlReminderUser2 when you are setting the selected values? Are there any items with the same value as that you are trying to set? What does getAdList() do? Commented Feb 15, 2018 at 23:49
  • Schandensbegrenzer: Yes it is 2 because the list has a total of three items. 0, 1 and 2. Jon P: Yes I set a BP and stepped through the code. It drops through to the Else statement for ddlReminderUser2 but for some reason it will not set it. Yes the list is populated before trying to set it. I can click the list after the page loads and see the list of names. Yes the item I am trying to set it to has a match in the list. getAdList pulls the list of user names from Active Directory and it works fine because the list is there in both drop down lists after page load. Commented Feb 16, 2018 at 3:36
  • Anybody have any ideas?? Commented Feb 16, 2018 at 16:15

1 Answer 1

1

This is how I finally figured it out.

I changed both of the drop down list boxes to .SelectedItem.Text = [What Ever Variable] and it now works great.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.