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 8586763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:23:30+00:00 2026-06-11T22:23:30+00:00

Im stuck in my project here and i really need some help! I have

  • 0

Im stuck in my project here and i really need some help!
I have 2 dropdownlists “DropDownPostal” and “DropDownCity”. When the user/employee logges into the system, he gets the list of Postals in the first dropdown list. Lets say he choose a postal and tabs over to the second dropdown “city”. I want city to be updated with the postal the user choose earlier. I have everything working with the login and retrieving data from the database to the DropDownPostal. But I cannot get the other DropDownCity updated with any data!

Here is my code for the event i made for the postaldropdown, Im trying to make a “onLeave” event.

  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
   using System.Web.UI;
   using System.Web.UI.WebControls;

 namespace Test
  {
public partial class WebForm1 : System.Web.UI.Page
{

    // Entity
    DanxWebsiteEntities dwe = new DanxWebsiteEntities();

    protected void Page_Load(object sender, EventArgs e)
    {


        //Dropdown postback
        //DropDownListPostal.AutoPostBack = false;

        //Sessions
        if (Session["UserID"] == null && Session["Name"] == null)
        {
            Response.Redirect("Error.aspx");
        }
        else
        {
            msg1.Text = "User id: "+Session["UserID"].ToString();
            msg2.Text = "User Name: " + Session["Name"].ToString();
        }   
        //Update dropdownpostal
        if (!IsPostBack)
        {
            //Guid is structure type 
            Guid id =(Guid) Session["UserID"];
            DropDownListPostal.DataSource = (from custumAdr in dwe.VW_CustumAddress
                                             where custumAdr.UserID ==(Guid)id
                                             select custumAdr).ToList();
            DropDownListPostal.DataTextField = "Postal";
            DropDownListPostal.DataValueField = "UserID";
            DropDownListPostal.DataBind();
        }
    }



    protected void DropDownListPostal_SelectedIndexChanged1(object sender, EventArgs e)
    {
        foreach (var data in dwe.VW_CustumAddress)
            if (data.Postal == DropDownListPostal.SelectedItem.ToString())
            {
                DropDownListBy.Text = data.City;

            }
            else
            {

            }
    }
    }

}

Im not even sure if this code is close to correct.
Detailed help with code will be much appreciated.

Cheers 🙂

  • 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-11T22:23:31+00:00Added an answer on June 11, 2026 at 10:23 pm

    If I understood you right, you only need to change the value displayed in dropDownListCity according to the value selected in dropDownListPostal. To do so, you need to bind both dropdown lists in Page_Load and then handle the selected index when SelectedIndexChanged is triggered.

    private IEnumerable<KeyValuePair<string, string>> GetData()
    {
        using(var dataContext = new DbEntities())
        {
            return dataContext.VW_CustumAddress 
                .ToList() 
                .Select(item => new KeyValuePair<string, string>(item.Postal, item.City))
                .ToArray();
        }
    }
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostback)
        {
            IEnumerable<KeyValuePair<string,string>> data = GetData();
            //Bind Postal dropdown list
            dropDownListPostal.DataSource = data.Select(kvp => kvp.Key).ToList();
            // ^ Select only 'Postal' column in dropdown list.
            dropDownListPostal.DataBind();
            // Bind City dropdown list
            // We need to bind to a key-value pair to know the correspondence between items
            dropDownListCity.DataValueField = "Key";
            dropDownListCity.DataTextField = "Value";
            dropDownListCity.DataSource = data;
            dropDownListCity.DataBind();
        }
    }
    

    Now, after you bound your controls to data you only need to handle SelectedIndexChanged event of dropDownListPostal (don’t forget to set AutoPostback="true" in the markup of dropDownListPostal).
    EDIT: Before selecting an item, clear the selection of your dropdown list to make sure only one item is selected.

    protected void OnDropDownListPostalSelectedIndexChanged(object sender, EventArgs e)
    {
        dropDownListCity.ClearSelection();
        var postal = dropDownListPostal.SelectedValue;
        var listItem = dropDownListCity.Items.FindByValue(postal);
        listItem.Selected = true;
    }
    

    That should do it. Hope it helps.

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

Sidebar

Related Questions

Hey, I'm really stuck with my project here... I need to know when any
I am having a weird problem here, and I am really stuck, need to
I am having a weird problem here, and I am really stuck, need to
I'm stuck with migrating my Django project to a production server. Here is the
Possible Duplicate: Need help solving Project Euler problem 200 Similar to this question Project
I ran into a new problem on my project; I have a panel on
I am really confused i have a directory structure as follows. /foo/bar/project/ under project
I have a very interesting challenge here for my Flex project development. I now
Im stuck with this little project in C# but basically my problem is this:
I've stuck myself in a c++ project under linux ,for which I get an

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.