Solved

populating Dropdown using another dropdown asp.net

Posted on 2003-10-21
4
262 Views
Last Modified: 2010-04-17
I have two combo boxes in asp.net page. One is state, another is City. When a State is selected, corresponding cities are populated in a city combo. I have fill all the states, city in a Js file as an array, calling it in a asp.net page.
The value of the City combo box is not persisting during the form postbacks which is my problem.

the following is loadcity function which loads all cities when a state is selected.

<!--

function Loadcity(stateidx)
 {
      var cmbcity = document.getElementById("cmbcity");
      stateidx--;
      if(stateidx >=1){
      for(i=0;i<city[stateidx].length;i++)
       {
            cmbcity.options[i] = new Option();
            cmbcity.options[i].text = city[stateidx][i][1];
            cmbcity.options[i].value = city[stateidx][i][0];
      }
      var num_cities = cmbcity.options.length;
      for(i=num_cities;i>city[stateidx].length;i--) {
            cmbcity.options[i-1] = null;}
      }
}

----------------------------

            <asp:DropDownList id="cmbcity" runat=server>
            <asp:listitem value="" text="Select City" />
              </asp:DropDownList>

--------------------------------

anyone could help me

Thanks
0
Comment
Question by:dkgopi
4 Comments
 
LVL 4

Accepted Solution

by:
Zonebit earned 125 total points
Comment Utility
Whenever you dynamically add items to a .net control using javascript, those values aren't seen server-side due to issues with the ViewState (I think).

A work around would be to add an HtmlInputHidden in your asp.net page, then copy the selected value from the city drop down box to the hidden field using javascript.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
changePi Challenge 15 75
nestparen challenge 4 55
VB6 Compile Compatibility Issue 4 23
Device same like our heart 12 42
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now