ASP.NET - filter dropdownlist based on other dropdownlist using xml file

Asked By aman on 20-Jan-12 01:23 AM

i have two dropdownlist control on my page and i want to filter one dropdownlist control based on the other dropdownlist using xml file 

please help me with an example..

smr replied to aman on 20-Jan-12 01:27 AM

follow this

Picture of two drop downs - state and city. 
You have one drop down labeled "State:" with the names of states and another drop-down labeled "City:" which gets populated with the names of the cities for the state you selected on the previous drop down.
The city drop-down obtains its values from an xml file which might look something like this:

  <City state="Washington">Redmond</City>
  <City state="Washington">Seattle</City>
  <City state="California">Los Angeles</City>
<City state="Florida">Orlando</City>
  1. In design mode, right click on the "City" drop down and open the Drop-down Properties dialog.
  2. Select to Look up values in a data connection to a database, Web Service, file, Share Point library or list.
  3. Click Add and follow the wizard to add the xml file containing the city data.
  4. After completing Data Connection Wizard, in the Entries field- select the source for the drop-down values by clicking the button on the right of the field. The Select a Field or Group dialog will appear, for this case you will select the "City" repeating group.
  5. Create a Filter by clicking the Filter Data... button and clicking Add... in the Filter Data dialog.
  6. You will want to create a Filter that displays the data in which the "state" attribute is equal to the field corresponding to the "State:" drop-down (Remember that the field value is kept in the form's "Main" data source)  


Jitendra Faye replied to aman on 20-Jan-12 01:29 AM
As you told, for that you have to implement cascading of DropDownList,

Follow this link for cascading of DropDownList using XML file.

(using AJAX)

Using LINQ
D Company replied to aman on 20-Jan-12 01:33 AM
Hello Friend,

Here is best example i have found,this  will help you.

Riley K replied to aman on 20-Jan-12 01:51 AM

If i tell you how to bind a ddl from XML i think it would be sufficient

Take a list of type Country and define properties, populate from xml like this

public List<Country> FetchCountries()
    List<Country> lstCountry = new List<Country>();
    XmlDocument xDoc = new XmlDocument();
    XmlElement root = xDoc.DocumentElement;
    XmlNodeList nodeList = root.GetElementsByTagName("country");
    for (int i = 0; i < nodeList.Count; i++)
       String countryName = String.Empty;
       countryName = nodeList[i].Attributes["name"].Value;
       lstCountry.Add(new Country { CountryID = i, CountryName = countryName });
    return lstCountry;