Home > DeveloperSection > Forums > Populate drop downlist with an xml file
jacob rasel
jacob rasel

Total Post:88

Posted on    May-20-2013 8:59 AM

 ASP.Net ASP.Net 

 1 Reply(s)
 1140  View(s)
Rate this:
Hi Developers,

I have two dropdownlist in my app country and state and i have to populate them through an xml file.
I have written the following code: 

ds = new DataSet();

public void LoadCountryDropdownList()
                ddlCountry.DataTextField = "name";
                ddlCountry.DataValueField = "country_Id";
                ddlCountry.DataSource = ds.Tables["country"];

private void LoadStateDropdownList(string country_Id)

through this code i have achieved data reading from an xml file is done 
and i have also populate the country dropdownlist list
now i have to populate the state dropdownlist list on the basis of country dropdownlist.

Thanks in advance.

Sumit Kesarwani

Total Post:378

Posted on    May-20-2013 9:04 AM

Hi Jacob,

try this code in your app

        ddlState.DataTextField = "state_Text";
                DataView dv = new DataView(ds.Tables["state"]);
                dv.RowFilter = "country_Id = " + country_Id;
                ddlState.DataSource = dv.ToTable();

I hope this code will solve your problem.

Don't want to miss updates? Please click the below button!

Follow MindStick