回答編集履歴

1

サンプル追記

2016/10/09 00:10

投稿

退会済みユーザー
test CHANGED
@@ -3,3 +3,187 @@
3
3
 
4
4
 
5
5
  xml から DataSet / DataTable を作る方法は xml datatable などをキーワードにググると多々ヒットしますので、ご自分で調べてみてください。いろいろ参考になる記事が見つかると思います。
6
+
7
+
8
+
9
+ 【2016/10/9 9:10 追記】
10
+
11
+
12
+
13
+ XmlDataSource を使って、その Data プロパティに文字列を設定するサンプルを追記しておきます。
14
+
15
+
16
+
17
+ ```
18
+
19
+ <%@ Page Language="C#" %>
20
+
21
+
22
+
23
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
24
+
25
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
26
+
27
+
28
+
29
+ <script runat="server">
30
+
31
+
32
+
33
+ protected void Page_Load(object sender, EventArgs e)
34
+
35
+ {
36
+
37
+ XmlDataSource1.Data = @"
38
+
39
+
40
+
41
+ <?xml version=""1.0"" encoding=""utf-8"" ?>
42
+
43
+ <Products>
44
+
45
+ <Product
46
+
47
+ ProductID=""1""
48
+
49
+ ProductName=""Chai""
50
+
51
+ QuantityPerUnit=""10 boxes x 20 bags""
52
+
53
+ UnitPrice=""18.0000""
54
+
55
+ UnitsInStock=""39"" />
56
+
57
+ <Product
58
+
59
+ ProductID=""2""
60
+
61
+ ProductName=""Chang""
62
+
63
+ QuantityPerUnit=""24 -12 oz bottles""
64
+
65
+ UnitPrice=""19.0000""
66
+
67
+ UnitsInStock=""17"" />
68
+
69
+ <Product
70
+
71
+ ProductID=""3""
72
+
73
+ ProductName=""Aniseed Syrup""
74
+
75
+ QuantityPerUnit=""12 -550 ml bottles""
76
+
77
+ UnitPrice=""10.0000""
78
+
79
+ UnitsInStock=""13"" />
80
+
81
+ <Product
82
+
83
+ ProductID=""4""
84
+
85
+ ProductName=""Chef Anton's Cajun Seasoning""
86
+
87
+ QuantityPerUnit=""48 - 6 oz jars""
88
+
89
+ UnitPrice=""22.0000""
90
+
91
+ UnitsInStock=""53"" />
92
+
93
+ <Product
94
+
95
+ ProductID=""5""
96
+
97
+ ProductName=""Chef Anton's Gumbo Mix""
98
+
99
+ QuantityPerUnit=""36 boxes""
100
+
101
+ UnitPrice=""21.3500""
102
+
103
+ UnitsInStock=""0"" />
104
+
105
+ </Products>
106
+
107
+
108
+
109
+ ";
110
+
111
+
112
+
113
+ }
114
+
115
+ </script>
116
+
117
+
118
+
119
+ <html xmlns="http://www.w3.org/1999/xhtml">
120
+
121
+ <head runat="server">
122
+
123
+ <title></title>
124
+
125
+ </head>
126
+
127
+ <body>
128
+
129
+ <form id="form1" runat="server">
130
+
131
+ <div>
132
+
133
+ <asp:XmlDataSource ID="XmlDataSource1" runat="server">
134
+
135
+ </asp:XmlDataSource>
136
+
137
+ <asp:GridView ID="GridView1" runat="server"
138
+
139
+ DataSourceID="XmlDataSource1"
140
+
141
+ AutoGenerateColumns="False">
142
+
143
+ <Columns>
144
+
145
+ <asp:BoundField HeaderText="ProductID"
146
+
147
+ DataField="ProductID" SortExpression="ProductID">
148
+
149
+ </asp:BoundField>
150
+
151
+ <asp:BoundField HeaderText="ProductName"
152
+
153
+ DataField="ProductName"
154
+
155
+ SortExpression="ProductName">
156
+
157
+ </asp:BoundField>
158
+
159
+ <asp:BoundField HeaderText="QuantityPerUnit"
160
+
161
+ DataField="QuantityPerUnit"
162
+
163
+ SortExpression="QuantityPerUnit"></asp:BoundField>
164
+
165
+ <asp:BoundField HeaderText="UnitPrice"
166
+
167
+ DataField="UnitPrice"
168
+
169
+ SortExpression="UnitPrice"></asp:BoundField>
170
+
171
+ <asp:BoundField HeaderText="UnitsInStock"
172
+
173
+ DataField="UnitsInStock"
174
+
175
+ SortExpression="UnitsInStock"></asp:BoundField>
176
+
177
+ </Columns>
178
+
179
+ </asp:GridView>
180
+
181
+ </div>
182
+
183
+ </form>
184
+
185
+ </body>
186
+
187
+ </html>
188
+
189
+ ```