GridView使用LinkButton和Button两种方式的删除确认

方法1  

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    //如果是绑定数据行  
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
        {
            ((LinkButton)e.Row.Cells[1].Controls[2]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除吗?')");
        }
    }
}

 

方法2(测试成功)

 

 protected void GridView1_RowDataBound1(object sender, GridViewRowEventArgs e)
        {
            //如果是绑定数据行  
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
                {
                    LinkButton btn = (LinkButton)e.Row.FindControl("lbtly");
                    btn.Attributes.Add("onclick", "javascript:return confirm('你确认要删除吗?')");
                    btn.Text = "领用";
                }
            }

 

          

 

        }
     

 

你可能感兴趣的:(GridView)