using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections.Generic;
namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
public class NumberLinkTemplate : ITemplate
{
#region ITemplate 成员
public void InstantiateIn(Control container)
{
LinkButton lb = new LinkButton();
lb.CommandName = "Index";
Literal lt = new Literal();
lt.Text = " ";
container.Controls.Add(lb);
container.Controls.Add(lt);
lb.DataBinding += new EventHandler(lb_DataBinding);
}
void lb_DataBinding(object sender, EventArgs e)
{
LinkButton lbtn = (LinkButton)sender;
RepeaterItem container = (RepeaterItem)lbtn.NamingContainer;
lbtn.Text = container.DataItem.ToString();
lbtn.CommandArgument = container.DataItem.ToString();
}
#endregion
}
protected void Page_Load(object sender, EventArgs e)
{
List<string> linkNumberDataSource = new List<string>();
for (int i = 1; i <= 10; i++)
{
linkNumberDataSource.Add(i.ToString());
}
Repeater enterpriseRep = new Repeater();
enterpriseRep.ItemTemplate = new NumberLinkTemplate();
enterpriseRep.DataSource = linkNumberDataSource;
enterpriseRep.DataBind();
enterpriseRep.ItemCommand += new RepeaterCommandEventHandler(enterpriseRep_ItemCommand);
this.Panel1.Controls.Add(enterpriseRep);
}
void enterpriseRep_ItemCommand(object source, RepeaterCommandEventArgs e)
{
Response.Write("CommandName:"+e.CommandName+"<br>"+"CommandArgument:"+e.CommandArgument);
}
}
}