Khargesh Rajput

Khargesh Rajput

  • NA
  • 5.6k
  • 603k

how to select cities in listbox on dropdownlist index change

Jul 31 2013 9:44 PM
I have a dropdownlist for states.
and on selected index change  i want the cities of the selected state in listbox.
I have bind states in dropdownlist, but on selected index chnge i got only default value.

public void bindstate()
    {
        DataSet ds = new DataSet();
        ds = objdal.FillDataSet(CommandType.Text, "select * from state where active=1");
        //ddlstate.Items.Clear();
        //ddlstate.Items.Add("Select State");
        ddlstate.DataTextField = "statename";
        ddlstate.DataValueField = "StateId";
        ddlstate.DataSource = ds.Tables[0];
        ddlstate.DataBind();
        ddlstate.Items.Insert(0, new ListItem("-- Select State --", "0"));

and
DataSet ds = new DataSet();
        ds = objdal.FillDataSet(CommandType.Text, "select City_Name from City where State_id='"+ddlstate.SelectedValue+"'");
        listcity.DataSource = ds.Tables["City"];
        listcity.DataTextField = "City_name";
        listcity.DataValueField = "CityID";
        listcity.DataBind();
        listcity.Items.Insert(0,new ListItem("select city","0"));



obkdal is object of DAL

Answers (3)