那我怎么实现,事件委托呢?这个linkbutton总要让它干点事啊!!!
求助!!

解决方案 »

  1.   

    不要在InitializeComponent()里面加
    try((LinkButton)repeater1.FindControl("linkbutton1")).Click += new System.EventHandler(this.linkbutton1_Click);
      

  2.   

    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
      

  3.   

    private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
    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;
    }
    看看例子,差不多的,在这个函数里加一个事件吧
      

  4.   

    你这样用肯定报错嘛!
    既然是repeater的itemtemplete项,肯定要被复制多次的,你叫这个事件怎么区分是哪一项itemtemplete发出的动作呢?从这里入手吧。
      

  5.   

    再ItemDataBound 事件里
    ((LinkButton)repeater1.FindControl("linkbutton1")).Click += new System.EventHandler(this.linkbutton1_Click);
      

  6.   

    repeater控件不需要手动添加事件委托,只要在<itemtemplete>的<asp:LinkButton onClick="">中添加函数或操作就可以了