Hai all i wrote this one for country and states binding in dropdown countries dropdown is working fine but states drop down is not populating
protected void BindDdlCountry()
{
SqlConnection con = new SqlConnection(s);
con.Open();
SqlCommand cmd = new SqlCommand("select * from Tb_country", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
DdlCountry.DataSource = ds;
DdlCountry.DataTextField = "Country";
DdlCountry.DataValueField = "Id";
DdlCountry.DataBind();
DdlCountry.Items.Insert(0, new ListItem("--Select--", "0"));
DdlState.Items.Insert(0, new ListItem("--Select--", "0"));
}
___for States Dropdown__
int StateID = Convert.ToInt32(DdlCountry.SelectedIndex);
SqlConnection con = new SqlConnection(s);
con.Open();
SqlCommand cmd = new SqlCommand("select * from Tb_State where Country_Id_Pk='" + StateID + "'", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
DdlState.DataSource = ds;
DdlState.DataTextField = "StateName";
DdlState.DataValueField = "StateId";
DdlState.DataBind();
and i never assign any of primary keys in my tables
hope someone helps me
TIA