Solved

populating Dropdown using another dropdown asp.net

Posted on 2003-10-21
4
267 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

This is about my first experience with programming Arduino.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
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…

776 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