3
Answers

how to select cities in listbox on dropdownlist index change

Khargesh Rajput

Khargesh Rajput

11y
1.7k
1
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)