Preferred Language:
Listing 29.28 - ImageRotator.cs
using System;
using System.Collections;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
namespace myControls
{
[ParseChildren(true, "ImageItems")]
public class ImageRotator : WebControl
{
private ArrayList _imageItems = new ArrayList();
public ArrayList ImageItems
{
get
{
return _imageItems;
}
}
protected override void RenderContents(HtmlTextWriter writer)
{
if (_imageItems.Count > 0)
{
Random rnd = new Random();
ImageItem img = (ImageItem)_imageItems[rnd.Next(_imageItems.Count)];
writer.AddAttribute(HtmlTextWriterAttribute.Src, img.ImageUrl);
writer.AddAttribute(HtmlTextWriterAttribute.Alt, img.AlternateText);
writer.RenderBeginTag(HtmlTextWriterTag.Img);
writer.RenderEndTag();
}
}
}
public class ImageItem
{
private string _imageUrl;
private string _alternateText;
public string ImageUrl
{
get { return _imageUrl; }
set { _imageUrl = value; }
}
public string AlternateText
{
get { return _alternateText; }
set { _alternateText = value; }
}
}
}
Need ASP.NET and Visual Studio 2008 Training?
- Learn ASP.NET 3.5 from Stephen Walther, author of ASP.NET 3.5 Unleashed.
We've provided ASP.NET training for NASA, Lockheed Martin, the National Science Foundation, Verizon,
Boeing, the US House of Representatives, Kaiser, Petco, Mary Kay, and Microsoft.
Why not your company?
-
Receive a four day, hands-on, intensive workshop.
-
We fly to you, anywhere in the world.
-
We can bring our own laptops.
To learn more, visit the
Superexpert Training website.