Dear Sir,
https://www.aspsnippets.com/Articles/Cascading-DropDownList-for-CountryStateCity-in-ASPNet.aspx
according to this artical when page load then country bind sucess fully but when country changed then nothing show in dropdown (3).
i use this in master page
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div class="form-group location_select_option active_location_option">
<asp:DropDownList ID="ddlCountries" runat="server" AutoPostBack = "true" OnSelectedIndexChanged = "Country_Changed">
</asp:DropDownList>
<asp:DropDownList ID="ddlStates" runat="server" AutoPostBack = "true" OnSelectedIndexChanged = "State_Changed">
</asp:DropDownList>
<asp:DropDownList ID="ddlCities" runat="server">
</asp:DropDownList>
</div>
</ContentTemplate>
</asp:UpdatePanel>
on page load
if (!IsPostBack)
{
string query = "select country_id, name from countries";
BindDropDownList(ddlCountries, query, "Name", "country_id", "Select Country");
ddlStates.Enabled = false;
ddlCities.Enabled = false;
ddlStates.Items.Insert(0, new ListItem("Select State", "0"));
ddlCities.Items.Insert(0, new ListItem("Select City", "0"));
}
==========================
private void BindDropDownList(DropDownList ddl, string query, string text, string value, string defaultText)
{
string conString = ConfigurationManager.ConnectionStrings["easyshikshaConnectionString"].ConnectionString;
SqlCommand cmd = new SqlCommand(query);
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
con.Open();
ddl.DataSource = cmd.ExecuteReader();
ddl.DataTextField = text;
ddl.DataValueField = value;
ddl.DataBind();
con.Close();
}
}
ddl.Items.Insert(0, new ListItem(defaultText, "0"));
}
protected void Country_Changed(object sender, EventArgs e)
{
ddlStates.Enabled = true;
ddlCities.Enabled = true;
ddlStates.Items.Clear();
ddlCities.Items.Clear();
ddlStates.Items.Insert(0, new ListItem("Select State", "0"));
ddlCities.Items.Insert(0, new ListItem("Select City", "0"));
int countryId = int.Parse(ddlCountries.SelectedItem.Value);
if (countryId > 0)
{
string query = string.Format("select state_id, name from states where country_id = {0}", countryId);
BindDropDownList(ddlStates, query, "Name", "state_id", "Select State");
ddlStates.Enabled = true;
}
}
protected void State_Changed(object sender, EventArgs e)
{
ddlCities.Enabled = false;
ddlCities.Items.Clear();
ddlCities.Items.Insert(0, new ListItem("Select City", "0"));
int stateId = int.Parse(ddlStates.SelectedItem.Value);
if (stateId > 0)
{
string query = string.Format("select id, name from cities where state_id = {0}", stateId);
BindDropDownList(ddlCities, query, "CityName", "CityId", "Select City");
ddlCities.Enabled = true;
}
}
where i m wrong .. and in content page its working fine