質問するログイン新規登録

回答編集履歴

1

サンプル追記

2016/10/09 00:10

投稿

退会済みユーザー
answer CHANGED
@@ -1,3 +1,95 @@
1
1
  xml から DataSet / DataTable を作って、それを GridView にバインドしてはいかがでしょう?
2
2
 
3
- xml から DataSet / DataTable を作る方法は xml datatable などをキーワードにググると多々ヒットしますので、ご自分で調べてみてください。いろいろ参考になる記事が見つかると思います。
3
+ xml から DataSet / DataTable を作る方法は xml datatable などをキーワードにググると多々ヒットしますので、ご自分で調べてみてください。いろいろ参考になる記事が見つかると思います。
4
+
5
+ 【2016/10/9 9:10 追記】
6
+
7
+ XmlDataSource を使って、その Data プロパティに文字列を設定するサンプルを追記しておきます。
8
+
9
+ ```
10
+ <%@ Page Language="C#" %>
11
+
12
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
13
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
14
+
15
+ <script runat="server">
16
+
17
+ protected void Page_Load(object sender, EventArgs e)
18
+ {
19
+ XmlDataSource1.Data = @"
20
+
21
+ <?xml version=""1.0"" encoding=""utf-8"" ?>
22
+ <Products>
23
+ <Product
24
+ ProductID=""1""
25
+ ProductName=""Chai""
26
+ QuantityPerUnit=""10 boxes x 20 bags""
27
+ UnitPrice=""18.0000""
28
+ UnitsInStock=""39"" />
29
+ <Product
30
+ ProductID=""2""
31
+ ProductName=""Chang""
32
+ QuantityPerUnit=""24 -12 oz bottles""
33
+ UnitPrice=""19.0000""
34
+ UnitsInStock=""17"" />
35
+ <Product
36
+ ProductID=""3""
37
+ ProductName=""Aniseed Syrup""
38
+ QuantityPerUnit=""12 -550 ml bottles""
39
+ UnitPrice=""10.0000""
40
+ UnitsInStock=""13"" />
41
+ <Product
42
+ ProductID=""4""
43
+ ProductName=""Chef Anton's Cajun Seasoning""
44
+ QuantityPerUnit=""48 - 6 oz jars""
45
+ UnitPrice=""22.0000""
46
+ UnitsInStock=""53"" />
47
+ <Product
48
+ ProductID=""5""
49
+ ProductName=""Chef Anton's Gumbo Mix""
50
+ QuantityPerUnit=""36 boxes""
51
+ UnitPrice=""21.3500""
52
+ UnitsInStock=""0"" />
53
+ </Products>
54
+
55
+ ";
56
+
57
+ }
58
+ </script>
59
+
60
+ <html xmlns="http://www.w3.org/1999/xhtml">
61
+ <head runat="server">
62
+ <title></title>
63
+ </head>
64
+ <body>
65
+ <form id="form1" runat="server">
66
+ <div>
67
+ <asp:XmlDataSource ID="XmlDataSource1" runat="server">
68
+ </asp:XmlDataSource>
69
+ <asp:GridView ID="GridView1" runat="server"
70
+ DataSourceID="XmlDataSource1"
71
+ AutoGenerateColumns="False">
72
+ <Columns>
73
+ <asp:BoundField HeaderText="ProductID"
74
+ DataField="ProductID" SortExpression="ProductID">
75
+ </asp:BoundField>
76
+ <asp:BoundField HeaderText="ProductName"
77
+ DataField="ProductName"
78
+ SortExpression="ProductName">
79
+ </asp:BoundField>
80
+ <asp:BoundField HeaderText="QuantityPerUnit"
81
+ DataField="QuantityPerUnit"
82
+ SortExpression="QuantityPerUnit"></asp:BoundField>
83
+ <asp:BoundField HeaderText="UnitPrice"
84
+ DataField="UnitPrice"
85
+ SortExpression="UnitPrice"></asp:BoundField>
86
+ <asp:BoundField HeaderText="UnitsInStock"
87
+ DataField="UnitsInStock"
88
+ SortExpression="UnitsInStock"></asp:BoundField>
89
+ </Columns>
90
+ </asp:GridView>
91
+ </div>
92
+ </form>
93
+ </body>
94
+ </html>
95
+ ```