this is my xml file. i want to fill 3 dropdownboxes 1st with countries,2nd with its respective states,3rd with its respective cities. in asp.net 3.5 with c#
how should i do it? help me.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Bryian TanRank #396 · 6.3K reputationPosted Feb 10, 2010, 5:03 AM EST
You can read the XML into a DataSet and bind the DataTable to each DropDownList separately. For instance:
protected void Page_Load(object sender, EventArgs e) { DataSet ds = new DataSet(); ds.ReadXml(MapPath("~/app_data/countries.xml")); BindCountries(ds.Tables["country"]); BindStates(ds.Tables["state"]); BindCities(ds.Tables["city"]); } void BindCountries(DataTable dtblC) { ddlCountry.Items.Clear(); ddlCountry.DataSource = dtblC; ddlCountry.DataTextField = "name"; ddlCountry.DataValueField = "id"; ddlCountry.DataBind(); } void BindStates(DataTable dtblC) { ddlStates.Items.Clear(); ddlStates.DataSource = dtblC; ddlStates.DataTextField = "name"; ddlStates.DataValueField = "id"; ddlStates.DataBind(); } void BindCities(DataTable dtblC) { ddlCities.Items.Clear(); ddlCities.DataSource = dtblC; ddlCities.DataTextField = "name"; ddlCities.DataValueField = "id"; ddlCities.DataBind(); }Hope that helps.
Thanks,
Bryian Tan