<%@ Control Language="C#" ClassName="GalleryTable" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Xml" %>
<%@ OutputCache Shared="true" Duration="60" VaryByParam="none" %>

<script runat="server">
	//This variable specifies relative path to the folder, where the gallery with uploaded files is located.
	//Do not forget about the slash in the end of the folder name.
	string _galleryPath = "../Gallery/";

	private void Page_Load(System.Object sender, System.EventArgs e)
	{
		string fileName = Server.MapPath(_galleryPath + "Descriptions.xml");
		//Clear cache when Description.xml is changed		
		this.CachePolicy.Dependency = new CacheDependency(fileName);

		if (File.Exists(fileName))
		{
			XmlDocument descriptions = new XmlDocument();
			descriptions.Load(fileName);

			if (descriptions.DocumentElement.ChildNodes.Count > 0)
			{
				DataList1.DataSource = descriptions.DocumentElement.ChildNodes;
				DataList1.DataBind();
			}
		}
	}

	private string EncodeFileName(string value)
	{
		return Server.UrlEncode(value).Replace("+", "%20");
	}
</script>

<asp:DataList ID="DataList1" Width="100%" RepeatLayout="Table" RepeatDirection="Vertical"
	RepeatColumns="4" runat="server">
	<HeaderTemplate>
	</HeaderTemplate>
	<ItemTemplate>
		<a href="<%# _galleryPath + EncodeFileName(((XmlElement)(Container.DataItem)).GetAttribute("name")) %>"
			target="_blank">
			<img src="<%# _galleryPath + "Thumbnails/" + EncodeFileName(((XmlElement)(Container.DataItem)).GetAttribute("name")) + ".jpg"%>"
				alt="<%# Server.HtmlEncode(((XmlElement)(Container.DataItem)).GetAttribute("name"))%>"
				title="<%# Server.HtmlEncode(((XmlElement)(Container.DataItem)).GetAttribute("name"))%>" />
		</a>
		<br />
		<br />
		<b>Name:</b>
		<%# Server.HtmlEncode(((XmlElement)(Container.DataItem)).GetAttribute("name")) %>
		<br />
		<b>Dimensions:</b>
		<%# Server.HtmlEncode(((XmlElement)(Container.DataItem)).GetAttribute("width")) %>
		x
		<%# Server.HtmlEncode(((XmlElement)(Container.DataItem)).GetAttribute("height")) %>
		<br />
		<b>Description:</b>
		<%# Server.HtmlEncode(((XmlElement)(Container.DataItem)).GetAttribute("description")) %>
	</ItemTemplate>
	<FooterTemplate>
	</FooterTemplate>
</asp:DataList>