Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8732409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:26:02+00:00 2026-06-13T09:26:02+00:00

I have a dropdown list on my page (ddlProgram) which is populated via a

  • 0

I have a dropdown list on my page (ddlProgram) which is populated via a database query like so:

Using dbContext as IRFEntities = New IRFEntities
    Dim getPrograms = (From p in dbContext.IRF_Program _
                       Order By p.name _
                       Select p)
    ddlProgram.DataSource = getPrograms
    ddlProgram.DataTextField = "name"
    ddlProgram.DataValueField = "id"
    ddl.Program.DataBind()
End Using

So, for example, one might have a DataTextField of “Education” and an ID of “221”.

Now, I prepopulate the form with information about the individual visiting the site (if available) – including the dropdown list like so:

If getProspect IsNot Nothing Then
  If getProspect.user_id Is Nothing Then
    ddlProgram.SelectedValue = getProspect.Program
  End If
End If

The Program property contains a number that matches the ID of a Program. So, for example, this individual might have a Program of “221” which would match the “221” of Education mentioned above.

Currently the application successfully sets the SelectedValue to “221” for the DropDownList (ddlProgram), but the SelectedItem of the DDL remains the same (e.g., if it is initially “History” with an ID of “1” after the prepopulation it is “History” with an ID of “221”).

What I’m trying to make happen is that the SelectedItem is updated to item which corresponds with the SelectedValue. So, in the end, if the individual has “221” for “Education” selected when the form is prepopulated they would see Education as the selected item and the selected value would be set correctly, whereas right now the form is showing the wrong SelectedItem but has the right SelectedValue behind the scenes.

Here is a more complete idea of the code flow from the Page_Load event:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If Page.IsPostBack = False Then
        ' If prospect is coming from unique url
        Dim prospect_url As String = Page.RouteData.Values("value")
        ' Save prospect_url into session variable
        Session("prospect_url") = prospect_url
        Using dbContext As IRFEntities = New IRFEntities
            ' Prepopulate the programs dropdown.
            Dim getPrograms = (From p In dbContext.IRF_Program _
                            Order By p.name _
                             Select p)
            ddlProgram.DataSource = getPrograms
            ddlProgram.DataTextField = "name"
            ddlProgram.DataValueField = "id"
            ddlProgram.DataBind()
        End Using
        Using dbContext As IRFEntities = New IRFEntities
            ' Prepopulate the states dropdown.
            Dim getStates = (From p In dbContext.IRF_States _
                             Order By p.name _
                            Select p)
            ddlState.DataSource = getStates
            ddlState.DataTextField = "name"
            ddlState.DataValueField = "id"
            ddlState.DataBind()
        End Using
        Using dbContext As IRFEntities = New IRFEntities
            ' Grab info. about prospect based on unique url.
            Dim getProspect = (From p In dbContext.IRF_Prospects _
                              Where p.url = prospect_url _
                              Select p).FirstOrDefault
            ' If they have a record...
            If getProspect IsNot Nothing Then
                If getProspect.user_id Is Nothing Then
                    ' Prepopulate the form with their information.
                    ' These must have a value, so we need to make sure that no column is null in the database.
                    ddlProgram.SelectedValue = getProspect.program
                    txtFirst.Text = getProspect.first_name
                    txtLast.Text = getProspect.last_name
                    txtAddress.Text = getProspect.address
                    txtCity.Text = getProspect.city
                    ddlState.SelectedValue = getProspect.state
                    txtZip.Text = getProspect.zip
                    txtPhone.Text = getProspect.phone
                    txtEmail.Text = getProspect.email_address
                    txtYearEnrolling.Text = getProspect.enrolling_in
                Else
                    ' Redirect them to login.
                    Response.Redirect("login.aspx")
                End If
            End If
        End Using
    End If
End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T09:26:03+00:00Added an answer on June 13, 2026 at 9:26 am

    What you’re doing looks like it should work. If you put a breakpoint after the setting of the value and check the SelectedItem text and value, do they appear as expected or mismatched?

    Use the Immediate Window to check:

    ddlProgram.SelectedItem.Text
    ddlProgram.SelectedItem.Value
    

    If they appear the same then I would presume the binding code is being refired and the list is being regenerated with the first item being selected.

    To check this put a break point on the binding code and see if it is fired more than once and correct the order of the methods appropriately.

    ADDED:
    If it works on your local environment it should work when published, if the code is the same? Looking at your code, I’d start by seperating out some of the databinding code into seperate methods rather than have everything in Page_Load, one becuase it’s good practice and two because it will make debugging easier. Further than that I’m not sure what else to suggest.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a dropdown list that is populated when the page loads, like this:
Basically, I have populated a dropdown list using php from a database on a
I have a dropdown list that is populated on a content page like this
I have a php page with a dropdown list that is populated by a
I have a drop down list which is dynamically generated using ajax on page
I have created a dropdown list, which is working well in separate page: however,
I have a Dropdown List in the asp page which I bind it in
I currently have a dropdown list being populated with values from a database. I
I have a populated dropdown list from mysql on one page. What code should
Afternoon All, I have a dropdown list which extracts data from my SQL database

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.