Click here to Skip to main content
15,906,329 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
hi
I have 2 drop down lists, the first bound to a unit name and the second bound to a city name which are read from XML

public ActionResult Test()
        {

            string strXmlpath = Server.MapPath("~\\Models\\Location.xml");

            var unit=from u in XDocument .Load (strXmlpath ).Document .Descendants ("Unit") select u;
            List<SelectListItem> lst = new List<SelectListItem>();
            foreach (var u in unit)
            {
                if (u.Attribute("ID").Value == "2")
                {
                    var city = u.Elements("city");
                    foreach (var c in city)
                        lst.Add(new SelectListItem { Text = c.Attribute("Name").Value, Value = c.Attribute("ID").Value });
                }
               
            }

            ViewData["cites"] = lst;


            var model = new UnitViewModel
            {
                Units = from units in XDocument.Load(strXmlpath).Document.Descendants("Unit")


                        select new SelectListItem
                        {
                            Value = units.Attribute("ID").Value,
                            Text = units.Attribute("Name").Value
                        }
            };

            List<SelectListItem> items = new List<SelectListItem>();
            foreach (var v in model.Units)
            {
             

                    items.Add(new SelectListItem
                    {
                        Text = v.Text,
                        Value = v.Value
                    });
         
            }

            ViewData["xml"] = items;



            return View();
        }

but now when change the unit drop down list value,
the city dropdownlist should bind to the city Subset for the unit.

i know should use cascading drop down lists and json but i search in google and did not find reference or example which help me .
please help me?
EDIT: Fixed format, grammar.
Posted
Updated 26-Jun-11 5:42am
v2

1 solution

This link might help you with cascading dropdowns using WebMethods. To use JSON as datasource you might want to try this.

Hope this helps!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900