Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have 2 dropdownlist.one for country and another for city.if i select country india from 1st dropdown and pune from another dropdown it works.there is select option in dropdown if 2nd time i select select option then it gives error:cannot have multiple items selected in a dropdownlist..bt if i select another city then it works..plz help me?
Posted
Comments
Sampath Kumar Sathiya 14-Dec-12 0:23am    
Could please provide the code which you used to populate the second (state) drop down list?
Member 9027346 14-Dec-12 0:28am    
there is no code for second dropdownlist..i only displaying and selecting country and city.

Hello,
C#
dropdownlist1.Items.Clear()
is the solution.
Have a look at following links:
http://geekswithblogs.net/shahed/archive/2008/08/23/124652.aspx[^]
http://forums.asp.net/t/1774603.aspx/1[^]
 
Share this answer
 
Comments
__TR__ 14-Dec-12 0:34am    
My 5!
The OP can also try dropDownList.ClearSelection();
Vani Kulkarni 14-Dec-12 0:41am    
Thanks! :) Yes even clearselection can be used.
C#
private void BindCountry()
   {
       ddlCountry.DataSource = CountryList();// give datasource what ever you want
       ddlCountry.DataTextField = "CountryName";
       ddlCountry.DataValueField = "CountryId";
       ddlCountry.DataBind();
       ddlCountry.Items.Insert(0, new ListItem("Select", "0"));
       ddlCity.Items.Insert(0, new ListItem("Select", "0"));
   }
   private void BindCity()
   {
       ddlCity.Items.Clear();
       int cityid = Convert.ToInt32(ddlCountry.SelectedValue);
       ddlCity.DataSource = CityList(cityid);// give datasource what ever you want
       ddlCity.DataTextField = "CityName";
       ddlCity.DataValueField = "CityId";
       ddlCity.DataBind();
       ddlCity.Items.Insert(0, new ListItem("Select", "0"));
   }
   protected void ddlCountry_SelectedIndexChanged(object sender, EventArgs e)
   {
       BindCity();
   }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900