Read XML Data to GridView

时间:2016-04-04 17:47:18

标签: asp.net .net gridview

I have XML:

<BookList>
  <Book ID="1" Category="Science">
    <Title>test</Title>
    <Price>18.74</Price>
  </Book>
  <Book ID="2" Category="Drama">
    <Title>test2</Title>
    <Price>23.99</Price>
  </Book>
</BookList>

And I must use control GridView and display data:

ID | Title

1 test

2 test2

My code:

<asp:XmlDataSource ID="productsDataSource" 
                   Runat="server" 
                   DataFile="~/dane.xml">
</asp:XmlDataSource>
<asp:GridView ID="GridView1" Runat="server" 
              DataSourceID="productsDataSource" 
              AutoGenerateColumns="False">
  <Columns>
    <asp:BoundField HeaderText="ID" 
                    DataField="ID" 
                    SortExpression="ID">
    </asp:BoundField>
    <asp:BoundField HeaderText="Title" 
                    DataField="Title"
                    SortExpression="Title">
    </asp:BoundField>
  </Columns>
</asp:GridView>

But I get error: "not found field Title"

0 个答案:

没有答案