ASP 101 - Active Server Pages 101 photosxml.aspx
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Xml" %>
<script language="VB" runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
	Dim myXmlDocument         As XmlDocument
	Dim objPhotoList          As XmlNodeList
	Dim intPhotoCount         As Integer
	Dim I                     As Integer
	Dim mySortedList          As SortedList
	Dim intSelectedPhotoIndex As Integer
	Dim strPhotoId            As String
	Dim strPhotoTitle         As String
	' Pull the data from our XML file and put it into a
	' SortedList so we can play with it easily.
	myXmlDocument = New XmlDocument()
	myXmlDocument.Load(Server.MapPath("photos.xml"))
	' Get a list and count of photos in the XML file
	objPhotoList = myXmlDocument.getElementsByTagName("photo")
	intPhotoCount = objPhotoList.Count
	' Loop over the XmlNodeList copying data into
	' our SortedList
	mySortedList = New SortedList()
	For I = 0 To intPhotoCount - 1
		' childNodes: 0=id, 1=title
		mySortedList.Add( _
			objPhotoList.Item(I).childNodes(0).InnerXml, _
			objPhotoList.Item(I).childNodes(1).InnerXml)
	Next I
	objPhotoList = Nothing
	myXmlDocument = Nothing
	strPhotoId = Request.QueryString("photo")
	If strPhotoID = "" Then
		PhotoDetailPanel.Visible = False
		PhotoDataList.DataSource = mySortedList
		PhotoDataList.DataBind
	Else
		intSelectedPhotoIndex = mySortedList.IndexOfKey(strPhotoId)
		strPhotoTitle = mySortedList.GetByIndex(intSelectedPhotoIndex)
		litPhotoTitle.Text = strPhotoTitle
		imgPhoto.ImageUrl      = "photos/" & strPhotoId & ".thw.jpg"
		imgPhoto.AlternateText = strPhotoTitle
		If intSelectedPhotoIndex = 0 Then
			linkPrev.Visible     = False
		Else
			linkPrev.Visible     = True
			linkPrev.NavigateUrl = "photosxml.aspx?photo=" _
				& mySortedList.GetKey(intSelectedPhotoIndex - 1)
		End If
		If intSelectedPhotoIndex = mySortedList.Count - 1 Then
			linkNext.Visible     = False
		Else
			linkNext.Visible     = True
			linkNext.NavigateUrl = "photosxml.aspx?photo=" _
				& mySortedList.GetKey(intSelectedPhotoIndex + 1)
		End If
		PhotoDetailPanel.Visible = True
	End If
End Sub
</script>
<html>
<head>
<title>ASP.NET Photo Gallery (XML Version) Sample</title>
</head>
<body>
<form runat="server">
<h2>Photo Gallery (XML Version)</h2>
<asp:DataList id="PhotoDataList" runat="server"
	BorderWidth     = 1
	BorderColor     = "#000000"
	GridLines       = "Both"
	RepeatColumns   = 2
	RepeatDirection = "Horizontal"
>
	<ItemTemplate>
		<a href="photosxml.aspx?photo=<%# Container.DataItem.Key %>"
		><img src="photos/<%# Container.DataItem.Key %>.thm.jpg" border="0" /></a><br />
		<font size="-1"><%# Container.DataItem.Value %></font>
	</ItemTemplate>
</asp:DataList>
<asp:Panel id="PhotoDetailPanel" runat="server">
	<h3><asp:Literal id="litPhotoTitle" runat="server" /></h3>
	<p>
	<asp:Image id="imgPhoto" runat="server" />
	</p>
	<asp:HyperLink id="linkPrev" runat="server"
	Text = "<code><--</code> previous"
	/>
	   
	<asp:HyperLink id="linkNext" runat="server"
	Text = "next <code>--></code>"
	/>
	<p>
	<a href="photosxml.aspx">Back to the Main Photos Page</a>
	</p>
</asp:Panel>
</form>
<p>
Thumbnails and photos from <a href="http://www.photos.com/">Photos.com</a>.
They have over 180,000 royalty-free stock photographs available by subscription.
</p>
<hr />
<p>
Click <a href="http://www.asp101.com/samples/photosxml_aspx.asp">here</a>
to read about and download the source code.
</p>
</body>
</html>