Solved

populating Dropdown using another dropdown asp.net

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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.
A short article about problems I had with the new location API and permissions in Marshmallow
Simple Linear Regression
Starting up a Project

627 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