Displaying XML Data in a GridView and a ListBox? : XML GridView « XML « ASP.Net

Home
ASP.Net
1.ADO.net Database
2.Ajax
3.Asp Control
4.Collections
5.Components
6.Data Binding
7.Development
8.File Directory
9.HTML Control
10.Language Basics
11.Login Security
12.Mobile Control
13.Network
14.Page
15.Request
16.Response
17.Server
18.Session Cookie
19.Sitemap
20.Theme Style
21.User Control and Master Page
22.Validation by Control
23.Validation by Function
24.WebPart
25.WPF
26.XML
ASP.Net » XML » XML GridView 
Displaying XML Data in a GridView and a ListBox?


<%@ Page Language="C#" %>
<%@ Import Namespace="System.Xml" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Displaying XML Data in a GridView and a ListBox</title>
</head>
<body>    
    <form id="form1" runat="server">
    <div>
        <asp:ListBox ID="lstTitles" Runat="server" DataSourceID="bookSource" DataValueField="ISBN"
            DataTextField="Title"/>            
    </div>
    <div>
        <asp:GridView ID="bookView" Runat="server" DataSourceID="bookSource" AutoGenerateColumns="False">
            <Columns>
                <asp:BoundField HeaderText="ISBN" DataField="ISBN" SortExpression="ISBN"></asp:BoundField>
                <asp:BoundField HeaderText="Title" DataField="Title" SortExpression="Title"></asp:BoundField>
                <asp:BoundField HeaderText="Price" DataField="Price" SortExpression="Price"></asp:BoundField>
            </Columns>
        </asp:GridView>    
    </div>
    <div>
        <asp:XmlDataSource ID="bookSource" Runat="server" DataFile="~/Data.xml"
            XPath="Data/genre[@name ='Fiction']/book">
        </asp:XmlDataSource>&nbsp;</div>
    </form>
</body>
</html>
File: ~/Data.xml

<Data>
  <genre name="Fiction">
    <book ISBN="1" Title="title 1" Price="19.99" Discount="1.999">
      <chapter num="1" name="Introduction">
        Abstract...
      </chapter>
      <chapter num="2" name="Body">
        Abstract...
      </chapter>
      <chapter num="3" name="Conclusion">
        Abstract...
      </chapter>
    </book>
  </genre>
  <genre name="NonFiction">
    <book ISBN="2" Title="title 2" Price="27.95" Discount="2.795">
      <chapter num="1" name="Introduction">
        Abstract...
      </chapter>
      <chapter num="2" name="Body">
        Abstract...
      </chapter>
      <chapter num="3" name="Conclusion">
        Abstract...
      </chapter>
    </book>
  </genre>
</Data>

 
Related examples in the same category
1.asp:GridView column alignment
2.Load XML data to GridView
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.