Click here to Skip to main content
15,888,220 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi I'm developing a registration form with Country and city name .I need the city to be loaded in the dropdown list based on the selection in country dropdownlist.pls help me with this about what are all the code i should write in c# and help me with the SQL statements also for the records.I need to implement this using Store_procedures..help me with the code friends....
Posted

Try something on your own first ...

To start with check AJAX Control toolkit cascadingDropDown example

http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/CascadingDropDown/CascadingDropDown.aspx[^]
 
Share this answer
 
Did you try searching Google[^] before posting your question here? It returned About 133,000 results (0.40 seconds) for your query. Try using google first.

Top results for your query, Web form scenario:
Using CascadingDropDown with a Database[^]
populate-dropdown-based-selection-other[^]
introduction-here-i-will-explain-how-to[^]

Windows Form scenario:
http://csharpdotnetfreak.blogspot.com/2012/07/cascading-combobox-in-winforms-windows-forms.html[^]
 
Share this answer
 
hi, i solved it. this was the code.thanks for all the help...
C#
   public void Bind_ddlCountry()
   {
       SqlConObject.Open();
       SqlCommand cmd = new SqlCommand("sp_Country", SqlConObject);
       cmd.CommandType = CommandType.StoredProcedure;

       SqlDataReader dr = cmd.ExecuteReader();
       ddlCountry.DataSource = dr;
       ddlCountry.Items.Clear();
       ddlCountry.Items.Add("Select");
       ddlCountry.DataTextField = "Country_Name";
       ddlCountry.DataValueField = "Country_ID";
       ddlCountry.DataBind();
       SqlConObject.Close();
   }


   public void Bind_ddlCity(int countryid)
   {
       SqlConObject.Open();
       SqlCommand cmd = new SqlCommand("sp_City", SqlConObject);
       cmd.CommandType = CommandType.StoredProcedure;
       cmd.Parameters.Add("@Countryid", SqlDbType.Int).Value = countryid;
       SqlDataReader dr = cmd.ExecuteReader();
       ddlCity.DataSource = dr;
       ddlCity.Items.Clear();
       ddlCity.Items.Add("Select");
       ddlCity.DataTextField = "City_Name";
       ddlCity.DataValueField = "Country_ID";
       ddlCity.DataBind();
       SqlConObject.Close();
       
   }
}
  protected void ddlCountry_SelectedIndexChanged(object sender, EventArgs e)
    {
        Bind_ddlCity(int.Parse(ddlCountry.SelectedValue));
    }
 
Share this answer
 
v2
Comments
[no name] 13-Feb-15 5:50am    
kindly tell me i have the same isssue..what is ur view code how u call ddlCountry_SelectedIndexChanged...i have write the same code for my issue where u defined the ddlCountry_SelectedIndexChanged(

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