on page load the country dropdownlist is bind and working fine but after when i select the country than no state bind in state dropdownlist.
----------------------front end-----------------------------
--------------------------------code behind------------------------------
protected void Page_Load(object sender, EventArgs e)
{
if (con.State == ConnectionState.Closed)
{
con.Open();
}
if (!Page.IsPostBack)
{
getcountry();
}
}
protected void getcountry()
{
try
{
da = new SqlDataAdapter("select * from get_country", con);
ds = new DataSet();
da.Fill(ds);
ddlcountry.DataSource = ds;
ddlcountry.DataTextField = "conname";
ddlcountry.DataValueField = "conid";
ddlcountry.DataBind();
ddlcountry.Items.Insert(0, new ListItem("--Select--", "0"));
ddlstate.Items.Insert(0, new ListItem("--Select--", "0"));
}
catch (Exception ex)
{
Response.Write("error occurd :" + ex.Message.ToString());
}
finally
{
con.Close();
}
}
protected void ddlcountry_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
int conid = Convert.ToInt32(ddlcountry.SelectedItem.Value.ToString());
da = new SqlDataAdapter("select stateid,statename from get_state where conid=" + conid, con);
ds = new DataSet();
da.Fill(ds);
ddlstate.DataSource = ds;
ddlstate.DataTextField = "statename";
ddlstate.DataValueField = "stateid";
ddlstate.DataBind();
ddlstate.Items.Insert(0, new ListItem("---Select State---", "0"));
if (ddlstate.SelectedValue == "0")
{
ddlcity.Items.Clear();
ddlcity.Items.Insert(0,new ListItem("---Select City---","0"));
}
}
catch(Exception ex)
{
Response.Write("error occurd :" + ex.Message.ToString());
}
finally
{
con.Close();
}
}


Rajeesh MenothRank #118 · 18.4K reputationPosted Aug 19, 2016, 11:07 AM EDT
Midhun TpRank #388 · 6.5K reputationPosted Aug 19, 2016, 8:01 PM EDT
Inżynier Umair124 reputationPosted Aug 19, 2016, 10:00 PM EDT
Midhun TpRank #388 · 6.5K reputationPosted Aug 19, 2016, 10:35 PM EDT
Midhun TpRank #388 · 6.5K reputationPosted Aug 19, 2016, 10:37 PM EDT