【发布时间】:2014-03-07 09:56:46
【问题描述】:
我使用简单的 sql 表和程序来绑定我的 DropDownlist,但似乎需要一些时间来加载列表中的项目。所以现在我正在尝试将我的 DropDownList 与包含数据的 XML 文件文件绑定我想将我的 DropDownList 与..绑定。
我的代码
XElement main = XElement.Load(filePath);
IEnumerable<XElement> searched =
from c in main.Elements("GLCODE")
where (string)c.Element("GLCODEITEM").Attribute("PostingGL") == "200142"
select c;
DropDownList1.DataSource = searched;
DropDownList1.DataTextField = "GL";
DropDownList1.DataValueField = "PostingGL";
DropDownList1.DataBind();
我的 XML
<GLCODE>
<GLCODEITEM>
<PostingGL>200085</PostingGL>
<GL>200085 - Bank charges</GL>
</GLCODEITEM>
<GLCODEITEM>
<PostingGL>200089</PostingGL>
<GL>200089 - ROC FEES</GL>
</GLCODEITEM>
<GLCODEITEM>
<PostingGL>200098</PostingGL>
<GL>200098 - STAMP DUTY CHARGES</GL>
</GLCODEITEM>
<GLCODEITEM>
<PostingGL>200130</PostingGL>
<GL>200130 - Consumables - Backup Tapes</GL>
</GLCODEITEM>
<GLCODEITEM>
<PostingGL>200130</PostingGL>
<GL>200130 - Consumables - Miscellaneous</GL>
</GLCODEITEM>
<GLCODEITEM>
<PostingGL>200133</PostingGL>
<GL>200133 - ELECTRICITY EXPENSES</GL>
</GLCODEITEM>
<GLCODEITEM>
<PostingGL>200140</PostingGL>
<GL>200140 - PROFESSION TAX - COMPANY</GL>
</GLCODEITEM>
<GLCODEITEM>
<PostingGL>200142</PostingGL>
<GL>200142 - REPAIRS AND MAINTENANC</GL>
</GLCODEITEM>
</GLCODE>
问题是我的 DropDownList 中没有任何价值。 有人可以教我一些简单的方法来查询 XML 之类的吗 SELECT name,phoneno FROM Table WHERE Country="abc"
【问题讨论】: