我在GridView的FooterRow中添加的一个button控件,请问如何给这个button控件添加一个click事件?protected void outExcelBtn_Click(object sender, EventArgs e)
    {
        WebHelper.Alert("hello");
    }    protected void GridView1_DataBound(object sender, EventArgs e)
    {
        try
        {
            GridViewRow footerRow = GridView1.FooterRow;
            footerRow.Cells[0].ColumnSpan = 4;
            footerRow.Cells[1].Visible = false;
            footerRow.Cells[2].Visible = false;
            footerRow.Cells[3].Visible = false;            //新增控件
            Button btn = new Button();
            btn.ID = "myBtn";
            btn.Text = "<img src='../images/xls.gif' border=0 />生成Excel";
            btn.Click += new EventHandler(this.outExcelBtn_Click);
            footerRow.Cells[0].Controls.Add(btn);
        }
        catch
        {        }
    }

解决方案 »

  1.   

    在RowDataBound事件中。判断
    if (e.Row.RowType == DataControlRowType.Footer)
                {
                    LinkButton lbInsert = (LinkButton)e.Row.FindControl("你的控件ID");                
                }
      

  2.   

    在RowDataBound事件中。判断
    if (e.Row.RowType == DataControlRowType.Footer)
                {
                    LinkButton lbInsert = (LinkButton)e.Row.FindControl("你的控件ID");                
                }
      

  3.   

    参考:http://blog.csdn.net/insus/archive/2008/02/27/2123970.aspx
      

  4.   

    RowCommand 下边  我用的是linkbutton   if (e.CommandName == "SmallClass")
            {            try
                {                ClassModel.SD_ClassName = ((TextBox)ClassChild.FooterRow.FindControl("ClassName")).Text;
      if (Bll.Add(ClassModel) > 0)
                    {
                        ShowClass();
                    }
                }
                catch (Exception ex)
                {
                    ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('" + ex.Message.ToString().Replace("'", "") + "');</script>");
                }
            }