<%@ Import Namespace="System.Data" %>
<html>
<title>Retrieving XML Data Into a DataSet</title>
<link rel="stylesheet" href="/shared/netdemos.css">
<script language="C#" runat="server">
protected void Page_Load ( object src, EventArgs e ) {
// initialize dataset object
DataSet myData = new DataSet ( );
// read xml file into dataset
myData.ReadXml ( Server.MapPath ( "~/shared/books.xml" ) );
lstBooks.DataSource = myData;
lstBooks.DataBind ( );
}
void setBooks ( Object src, DataListItemEventArgs e ) {
if ( e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem ) {
DataRowView row = ( DataRowView ) e.Item.DataItem;
string altText = row [ "AlternateText" ].ToString ( );
HyperLink txtLink = ( HyperLink ) e.Item.FindControl ( "txtLink" );
txtLink.Text = altText.Length > 50 ? altText.Substring ( 0, 50 ) + "..." : altText;
}
}
</script>
<body>
<!-- #include virtual="~/shared/top.inc -->
<div class="header"><h2>ADO.NET Primer: Retrieving <span class="hilite">XML</span> Data Into a DataSet</h2></div>
<!-- #include virtual="~/shared/viewsrc_top.inc" -->
<hr size=1 width=92%>
<p align="center">
<form runat="server">
<asp:datalist id="lstBooks" runat="server"
width=96% font-size=9pt repeatcolumns=5
onitemdatabound="setBooks">
<itemstyle width=150 horizontalalign="center" />
<itemtemplate>
<table>
<tr align="center" valign="top">
<td valign="top">
<asp:hyperlink runat="server" target="_book"
imageurl='<%# Eval ( "ImageUrl" ) %>'
navigateurl='<%# Eval ( "NavigateUrl" ) %>'
tooltip='<%# Eval ( "AlternateText" ) %>' />
</td></tr>
<tr align="center" valign="top">
<td valign="top">
<asp:hyperlink id="txtLink" runat="server" target="_book"
navigateurl='<%# Eval ( "NavigateUrl" ) %>'
tooltip='<%# Eval ( "Keyword" ) %>' />
</td></tr>
</table>
</itemtemplate>
</asp:datalist>
</form>
</p>
<hr size=1 width=92%>
<!-- #include virtual="~/shared/viewsrc.inc" -->
</body>
</html>