不要在InitializeComponent()里面加 try((LinkButton)repeater1.FindControl("linkbutton1")).Click += new System.EventHandler(this.linkbutton1_Click);
add a ItemCommand event handler for the Repeater and set LinkButton s CommandName declaretively in the templateor try to bind the event handler in the Repeater's ItemDataBound event handler
try((LinkButton)repeater1.FindControl("linkbutton1")).Click += new System.EventHandler(this.linkbutton1_Click);
s CommandName declaretively in the templateor try to bind the event handler in the Repeater's ItemDataBound event handler
{
DataTable dt = new DataTable();
DataRow dr; dt.Columns.Add(new DataColumn("整数值", typeof(Int32)));
dt.Columns.Add(new DataColumn("字符串值", typeof(string))); for (int i = 1; i <= 9; i++)
{
dr = dt.NewRow();
dr[0] = i;
dr[1] = i.ToString()+"hello";
dt.Rows.Add(dr);
} DropDownList myDDList = (DropDownList)e.Item.Cells[6].FindControl("DropDownList1"); if(myDDList != null)
{
myDDList.Attributes.Add("onChange","alert(this.options[this.selectedIndex].value)");
myDDList.DataSource =dt.DefaultView;
myDDList.DataTextField=dt.Columns[1].ToString();
myDDList.DataValueField=dt.Columns[0].ToString();;
myDDList.DataBind();
myDDList.Items.FindByValue("5").Selected = true;
}
看看例子,差不多的,在这个函数里加一个事件吧
既然是repeater的itemtemplete项,肯定要被复制多次的,你叫这个事件怎么区分是哪一项itemtemplete发出的动作呢?从这里入手吧。
((LinkButton)repeater1.FindControl("linkbutton1")).Click += new System.EventHandler(this.linkbutton1_Click);