<?xml version="1.0" encoding="UTF-8"?>
<mmsdata>
<timestamp>Fri Jan 30 08:46:13 EST 2015</timestamp>
<mill n="AG" name="Augusta, GA">
<ds>
<server>agppra</server>
<server>agpprb</server>
</ds>
<mach n="1">
<srn n="1" calctype="2CV">RL.CLP (1)</srn>
&#13;
任何人都可以在此代码中看到错误,使其无法绑定到dropdownlist1吗?我重用了用于将int绑定到dropdownlist2的代码,但是这个代码不会绑定任何东西。如果你看不到错误,可以在我应该看的地方寻求帮助吗?
// Getting the XML file imported in
string filePath = @"C:\Projects\MEAS\Central\MillView\PVDA\Main\PVDA\PVDA.Web\MillData.xml";
// Set the file path
XDocument xDoc = XDocument.Load(filePath);
var dropDownDataList1 = GetMillInfo(xDoc, "AG");
// Bind your Mills to your DropDownList1
DropDownList1.DataSource = GetMillInfo(xDoc, "AG");
// Set your text / value properties
DropDownList1.DataTextField = "millName";
DropDownList1.DataValueField = "millInfo";
// Actually bind the contents to be reflected in the UI
DropDownList1.DataBind();
public List<Mill> GetMillInfo(XDocument xDoc, string millNameInfo)
{
return xDoc.XPathSelectElements("./mmsdata/mill")
.Where(x => x.Attribute("n").Value == millNameInfo)
.Elements()
.Select(x => new Mill
{
millInfo = x.Value,
millName = x.Attribute("n").Value
}).ToList();
}
&#13;