0
我想生成一個列表(字符串)作爲下拉列表的數據源使用。 我已經做了這麼多次,但這個版本並沒有像往常一樣分離出來。xmlnodelist下拉
下面是一個XML樣本
<fueltypes>
<fuel>
<type>Marine Diesel NY Harbor</type>
<dbheader>NYMarineDiesel</dbheader>
</fuel>
<fuel>
<type>ULSD NY Harbor</type>
<dbheader>NYULSD</dbheader>
</fuel>
</fueltypes>
下面是
Public Shared Function GetFuelTypes(ddlControl As Control) As List(Of String)
Dim doc As New XmlDocument()
'Load XML from the file into XmlDocument object
doc.Load("H:\OtherDataFiles\dataXML.xml") 'this needs to be changed to the server path
Dim root As XmlNode = doc.DocumentElement
'Select all nodes with the tag paramter indicated by the nodestring variable
Dim nodeList As XmlNodeList = root.SelectNodes("fueltypes")
Return (From node As XmlNode In nodeList Select node.InnerText).ToList()
End Function
他們獲取綁定到下拉菜單中的功能如下
'load the fuel types into the dropdownlist
ddlFuelTypes.DataSource = GetFuelTypes()
ddlFuelTypes.DataBind()
ddlFuelTypes.SelectedIndex = 1
下拉顯示一個所有項目line
注:/在不需要/ fueltypes /燃料/類型的字符串的前面,並且會導致錯誤,在代碼行昏暗節點列表作爲XmlNodeList中= root.SelectNodes(「/ fueltypes /燃料/鍵入「) – dinotom
它一旦移除就可以正常工作 – dinotom