protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SqlDataAdapter ad = new SqlDataAdapter("select Fname,id from x",con);
DataTable dt = new DataTable();
ad.Fill(dt);
if(dt.Rows.Count>0)
{
uxCountry.DataSource=dt;
uxCountry.DataTextField = "Fname";
uxCountry.DataTextField = "id";
uxCountry.DataBind();
}
}
}
protected void uxCountry_SelectedIndexChanged(object sender, EventArgs e)
{
uxStates.Items.Clear();
SqlDataAdapter ad = new SqlDataAdapter("select Lname,yid from y where xid=" + uxCountry.Items[uxCountry.SelectedIndex].Value, con);
DataTable dt = new DataTable();
ad.Fill(dt);
if (dt.Rows.Count > 0)
{
uxStates.DataSource = dt;
uxStates.DataTextField = "Lname";
uxStates.DataTextField = "yid";
uxStates.DataBind();
}
}
I tried this to filled the two dropdown Country and its states,it works well for me while postback on submit.