如何给在UpdatePanel内的GridView的按钮列添加Click事件?
我看了些原来03DataGrid的Demo,DataGrid只需在ItemCreated事件给按钮添加事件就成
但在05里,我往RowCreated写添加事件,没起一点作用,想请各位大侠帮忙指点指点~~
Demo:
 protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        Button btn = e.Row.FindControl("btnDetail") as Button;
        if (btn != null)
        {
            //btn.Attributes.Add("onclick", "javascript:window.open('Default2.aspx');");
            btn.Attributes.Add("onClick", "function a(){alert('ddd');}");
        }
    }

解决方案 »

  1.   

    谢谢Jennydin的建议,有时间一定会好好看的。~~
    现在想请各位大侠先帮我解决这个问题,多谢了~
      

  2.   

    把添加按钮客户端点击的脚本放到gridview的rowdatabound事件中
      

  3.   

    rowcreated时候可能取不到容器内部的控件,导致你的脚本没有输出到页面上
      

  4.   

    yan63,你的方法我试过了,还是不行哦~~
      

  5.   

    试试在数据绑定时添加click事件
    将RowCreated改为OnRowDataBoundprotected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //是否删除
                LinkButton bt = (LinkButton)e.Row.Cells[1].Controls[0];
               bt.Attributes.Add("onclick", "if(confirm('你确认要删除吗?')){}else{return false;}");        }
        }
      

  6.   

    谢谢wyw1997,用你的方法测试通过~
    不过结合起项目,报了一个“Input string was in a correctt format”
    ~~~-:)