如何给在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');}");
}
}
我看了些原来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');}");
}
}
现在想请各位大侠先帮我解决这个问题,多谢了~
将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;}"); }
}
不过结合起项目,报了一个“Input string was in a correctt format”
~~~-:)