1: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
2:
3: Dim xmlDoc1 As New XmlDocument
4: Dim dtValues1 As New DataTable("values")
5: dtValues1.Columns.Add(New DataColumn("key", Type.GetType("System.String")))
6: xmlDoc1.LoadXml(My.Resources.XML1)
7: ' Cerca i nodi relativi ai valori
8: Dim xmlNodes1 As XmlNodeList = xmlDoc1.SelectNodes("//values/value")
9: If Not xmlNodes1 Is Nothing Then
10: For i As Integer = 0 To xmlNodes1.Count - 1
11: dtValues1.Rows.Add(New String() {xmlNodes1(i).Attributes("key").Value})
12: Next
13: End If
14: Dim dsValues1 As New DataSet
15: dsValues1.Tables.Add(dtValues1)
16: Me.DropDownList1.DataSource = dsValues1
17: Me.DropDownList1.DataMember = "values"
18: Me.DropDownList1.DataValueField = "key"
19: Me.DropDownList1.DataTextField = "key"
20: Me.DropDownList1.DataBind()
21: dsValues1.Dispose()
22: dsValues1 = Nothing
23:
24: Dim xmlDoc2 As New XmlDocument
25: Dim dtValues2 As New DataTable("values")
26: dtValues2.Columns.Add(New DataColumn("key", Type.GetType("System.String")))
27: xmlDoc2.LoadXml(My.Resources.XML2)
28: ' Cerca i nodi relativi ai valori
29: Dim xmlNodes2 As XmlNodeList = xmlDoc2.SelectNodes("//values/value")
30: If Not xmlNodes2 Is Nothing Then
31: For i As Integer = 0 To xmlNodes2.Count - 2
32: dtValues2.Rows.Add(New String() {xmlNodes2(i).Attributes("key").Value})
33: Next
34: End If
35: Dim dsValues2 As New DataSet
36: dsValues2.Tables.Add(dtValues2)
37: Me.DropDownList2.DataSource = dsValues2
38: Me.DropDownList2.DataMember = "values"
39: Me.DropDownList2.DataValueField = "key"
40: Me.DropDownList2.DataTextField = "key"
41: Me.DropDownList2.DataBind()
42: dsValues2.Dispose()
43: dsValues2 = Nothing
44:
45: End Sub