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

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

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..

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

follow this

Example
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:

<Cities>
  <City state="Washington">Redmond</City>
  <City state="Washington">Seattle</City>
  <City state="California">Los Angeles</City>
 
<City state="Florida">Orlando</City>
</Cities>
Implementation
  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)  

refer
http://blogs.msdn.com/b/infopath/archive/2004/03/24/create-dependent-drop-down-list-box-in-infopath-using-filters.aspx

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.


http://forums.asp.net/p/1589808/4030867.aspx#4030867

(using AJAX)
http://www.ezineasp.net/post/AJAX-Cascading-Dropdown-Example-using-XML-Data.aspx

Using LINQ
http://naspinski.net/post/Cascading-DropDowns-using-XML-and-LINQ.aspx
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.



http://msmvps.com/blogs/benwalters/archive/2007/08/05/filtered-drop-down-lists-101.aspx

Regards
D
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();
    xDoc.Load(xmlPath);
    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;
}


Regards