<%@ Page Language="c#" %>
<%@ Register TagPrefix="Control" Namespace="Control" Assembly="Control" %>
Default
File: Control.cs
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Collections;
using System.Text;
namespace Control
{
[DefaultProperty("DataSource"),
ToolboxData("<{0}:CustomBulletedList runat=\"server\">{0}:CustomBulletedList>")]
public class CustomBulletedList : System.Web.UI.WebControls.WebControl
{
private StringBuilder _html = new StringBuilder();
private IEnumerable _dataSource;
[Bindable(true),
Category("Data"),
DefaultValue(null),
Description("The data source used to build up the bulleted list."),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public IEnumerable DataSource {
get {
return _dataSource;
}
set {
_dataSource = value;
}
}
private void CreateBulletedList()
{
IEnumerable dataSource = null;
try {
dataSource = this._dataSource;
} catch {
dataSource = null;
}
if (dataSource != null)
{
_html.Append("");
foreach (object dataObject in dataSource)
{
_html.Append("- ");
_html.Append(dataObject.ToString());
_html.Append(" ");
}
_html.Append("
");
}
}
public override void DataBind()
{
base.OnDataBinding(EventArgs.Empty);
CreateBulletedList();
}
protected override void Render(HtmlTextWriter output)
{
output.Write(_html);
}
}
}