• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 346
  • Last Modified:

copying value of an asp dropdownlist to another dropdownlist on same form

Hi experts,

I'm using visual studio 2010 and sql server.

I have asp.net application using VB as the language.

So I have a web form with some with these asp controls on it.
A user enters the items in. If their Mailing Address is the same as their physical address
then they check the checkbox and the Physical Addres, Physical City, Physical State, and Physical ZipCode are copied from those textboxes and dropdownlist and then fill the mailing ones.

Textbox:            FirstName
Textbox:            LastName
Textbox:            Physical Address
Textbox:             Physical City
DropDownList:   Physical State
Textbox:             Physical Zip Code

Checkbox:  Mailing Address Same As Physical      

Textbox:            Mailing Address      
Textbox:            Mailing City
DropDownList:  Mailing State      
Textbox:            Mailing Zip Code

All the textboxes are varchar(100)
The dropdownlist contain int value, they are the PhysicalState_PK and MailingState_PK columns from the CustomerTable

The data comes from a table called CustomerTable which looks something like this:

the PhysicalState and MailingState columns from the customer table use the value in those columns to lookup the state from the table called StatesTable which looks like this:

States table

In my form I have a checkbox event called Protected Sub cboxPhysicalAsMailing_CheckedChanged

I have an if statement that looks like this:

If (cboxPhysicalAsMailing.Checked) Then

            Me.txtMailingAddr.Text = txtPhysicalAddr.Text
            Me.txtMailingCity.Text = txtPhysicalCity.Text
            Me.ddlMailingStates.SelectedIndex = ddlPhysicalStates.SelectedIndex
            Me.txtMailingZipCode.Text = txtPhysicalZipCode.Text

So when I check the checkbox I want all the values from the Physical items copied to the Mailing items on the form.

When I check the checkbox I notice that all the values of the textboxes are copied successfully but the only one not working is the dropdownlist called ddlMailingStates.

How would I handle copying the value from the dropdownlist called ddlPhysicalStates and then filling my dropdownlist called ddlMailingStates with the same value?
1 Solution
for setting selected item in ddlMailingStates, you have to first add option items in that.
I mean, onlyafter having option items in ddlMailingStates, you can set selected index/value of that DropdownList.

For that you can refer below logic:

Option 1: While adding/binding option items to ddlPhysicalStates, add/bind same datasource to ddlMailingStates.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now