Solved

populating Dropdown using another dropdown asp.net

Posted on 2003-10-21
4
264 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
ID: 9599363
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB 6.0 printer how to align 6 57
nestparen challenge 4 72
Help to convert powershell script into a gui 9 134
Base1 Encode/Decode 3 67
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
This is about my first experience with programming Arduino.
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 …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

932 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