日期:2014-05-20 浏览次数:20830 次
XElement root = XElement.Load(Server.MapPath("~/1.xml")); var query = from f in root.Elements("CerType") select new { TypeID = f.Element("TypeID").Value, TypeName = f.Element("TypeName").Value }; DropDownList1.DataValueField = "TypeID"; DropDownList1.DataTextField = "TypeName"; DropDownList1.DataSource = query.ToList(); DropDownList1.DataBind();
------解决方案--------------------
XDocument doc = XDocument.Load("c:\\1.txt"); var vv = from r in doc.Descendants("CerType") select r; var vs = from r in doc.Descendants("CerType") select new { id = r.Element("TypeID").Value, name = r.Element("TypeName").Value }; comboBox1.DisplayMember = "id";//或者是"name" comboBox1.DataSource = vs.ToArray();