520202020020000.XML文件:
1<?xml version="1.0" encoding="gb2312" ?>
2<dev_rtdata>
3 <devandrtdata>
4 <cgqbh>01A01</cgqbh>
5 <cgqwz>11127回风风流</cgqwz>
6 <sjlx>模拟量</sjlx>
7 <jclx>瓦斯</jclx>
8 <sz>0</sz>
9 <dw>%</dw>
10 <zt>分站故障</zt>
11 <sj>2008-07-02 09:23:01</sj>
12 </devandrtdata>
13 <devandrtdata>
14 <cgqbh>01A02</cgqbh>
15 <cgqwz>11127回风回风流</cgqwz>
16 <sjlx>模拟量</sjlx>
17 <jclx>瓦斯</jclx>
18 <sz>0</sz>
19 <dw>%</dw>
20 <zt>分站故障</zt>
21 <sj>2008-07-02 09:23:01</sj>
22 </devandrtdata>
23</dev_rtdata>
2<dev_rtdata>
3 <devandrtdata>
4 <cgqbh>01A01</cgqbh>
5 <cgqwz>11127回风风流</cgqwz>
6 <sjlx>模拟量</sjlx>
7 <jclx>瓦斯</jclx>
8 <sz>0</sz>
9 <dw>%</dw>
10 <zt>分站故障</zt>
11 <sj>2008-07-02 09:23:01</sj>
12 </devandrtdata>
13 <devandrtdata>
14 <cgqbh>01A02</cgqbh>
15 <cgqwz>11127回风回风流</cgqwz>
16 <sjlx>模拟量</sjlx>
17 <jclx>瓦斯</jclx>
18 <sz>0</sz>
19 <dw>%</dw>
20 <zt>分站故障</zt>
21 <sj>2008-07-02 09:23:01</sj>
22 </devandrtdata>
23</dev_rtdata>
Default.aspx页面:
1<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
2
3<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4
5<html xmlns="http://www.w3.org/1999/xhtml" >
6<head runat="server">
7 <title>XmlDataSource控件绑定GridView</title>
8</head>
9<body>
10 <form id="form1" runat="server">
11 <div>
12 <asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/DataMonitor/520202020020000.XML">
13 </asp:XmlDataSource>
14
15 </div>
16 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="XmlDataSource1">
17 <Columns>
18 <asp:TemplateField HeaderText="cgqbh">
19 <ItemTemplate>
20 <%# XPath("cgqbh") %>
21 </ItemTemplate>
22 </asp:TemplateField>
23 <asp:TemplateField HeaderText="sz">
24 <ItemTemplate>
25 <%# XPath("sz") %>
26 </ItemTemplate>
27 </asp:TemplateField>
28 </Columns>
29 </asp:GridView>
30 </form>
31</body>
32</html>
33
2
3<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4
5<html xmlns="http://www.w3.org/1999/xhtml" >
6<head runat="server">
7 <title>XmlDataSource控件绑定GridView</title>
8</head>
9<body>
10 <form id="form1" runat="server">
11 <div>
12 <asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/DataMonitor/520202020020000.XML">
13 </asp:XmlDataSource>
14
15 </div>
16 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="XmlDataSource1">
17 <Columns>
18 <asp:TemplateField HeaderText="cgqbh">
19 <ItemTemplate>
20 <%# XPath("cgqbh") %>
21 </ItemTemplate>
22 </asp:TemplateField>
23 <asp:TemplateField HeaderText="sz">
24 <ItemTemplate>
25 <%# XPath("sz") %>
26 </ItemTemplate>
27 </asp:TemplateField>
28 </Columns>
29 </asp:GridView>
30 </form>
31</body>
32</html>
33