Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

populating Dropdown using another dropdown asp.net

Posted on 2003-10-21
4
Medium Priority
?
284 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 4

Accepted Solution

by:
Zonebit earned 500 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Introduction to Processes

660 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